2 条题解
-
1
#include <bits/stdc++.h> using namespace std; int main() { string s,p = ""; getline(cin,s); int u = s.size(); for (int i = 1;i <= 3 - (u - 1) % 4;i++)//补0 { u++; p += '0'; } p += s; for (int i = 3;i < u;i += 4) { int f = 8 * (p[i - 3] - '0') + 4 * (p[i - 2] - '0') + 2 * (p[i - 1] - '0') + p[i] - '0'; if (f > 10) { cout << (char)(f - 10 + 'A'); } else { cout << (char)(f + '0'); } } }
-
0
#include <bits/stdc++.h> using namespace std; string n; long long binary1(string x,int y){ long long sum=0,t=1; for (int i=(int)n.size()-1;i>=0;i--){ if (isalpha(n[i]))sum+=(n[i]-'A'+10)*t; else if (isdigit(n[i]))sum+=(n[i]-'0')*t; t*=y; } return sum; } string binary2(long long x,int y){ if (x==0)return "0"; string rep; while (x>0){ int g=x%y; if (g<10)rep+=(g+'0'); else rep+=((char)g-10+'A'); x/=y; } reverse(rep.begin(),rep.end()); return rep; } int main(){ cin>>n; cout<<binary2(binary1(n,2),16); return 0; }
- 1
信息
- ID
- 291
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- 1
- 标签
- 递交数
- 39
- 已通过
- 29
- 上传者