爱玲姐姐 5 years ago
parent
commit
e8a28b1ce1
1 changed files with 36 additions and 0 deletions
  1. 36 0
      F.cpp

+ 36 - 0
F.cpp

@@ -0,0 +1,36 @@
+#include<bits/stdc++.h>
+using namespace std;
+void to2(int n){
+    string s="00000000";
+    int t=7;
+    while(n){
+        s[t--]='0'+n%2;
+        n/=2;
+    }
+    cout<<s;
+}
+int main(){
+    string s;
+    //freopen("1.txt","r",stdin);
+    while(cin>>s){
+        if(s.find('.')<s.size()){
+             int a[4];
+             sscanf(s.c_str(),"%d.%d.%d.%d",&a[0],&a[1],&a[2],&a[3]);
+             for(int i=0;i<4;i++)
+                 to2(a[i]);
+        }
+        else{
+             int k[8]={128,64,32,16,8,4,2,1},sum=0,t=0,flag=1;
+             for(int i=0;i<s.size();i++){
+                 sum=sum+(s[i]-'0')*k[t++];
+                 if(t==8){
+                    t=0;
+                    flag?cout<<sum:cout<<"."<<sum;
+                    flag=0;
+                    sum=0;
+                 }
+             }
+        }
+        cout<<endl;
+    }
+}