9 条题解
-
0
$\texttt{\large\color{#12a1e8}本蒟蒻的第六篇\color{#92a1e8}题\color{#92b1d8}解}$
我们首先要理解进制转换的含义,很简单,每一位求出来,乘以权值,加起来即可(这是笔者第一次被卡住的题目,
虽然依旧是全班最先解决的人)
ord()
可以用于求字符串ASCII码,以此进行转换思路:从左到右算,加到
summ
中,每向右一位就乘以对应权值即可a=str(input()) n=0 summ=0 while n<len(a): summ*=16 if(a[n]>='0' and a[n]<='9'): summ+=ord(a[n])-ord('0') else: if(a[n]>='a' and a[n]<='f'): summ+=ord(a[n])-ord('a')+10 else: summ+=ord(a[n])-ord('A')+10 n+=1 print(summ)
首次做这题的代码,码风欠佳,与python写法不同,思路是求出每一位的值,在最后统一计算
#include <bits/stdc++.h> using namespace std; const int maxn=1000; string x; long long a,b[maxn],c[maxn],d,i,max,q,w,e,r,t,y,u,o,p; int main(){ cin>>x; i=0; while(i<x.length()){ if(x[i]>='0'&&x[i]<='9'){ b[i]=x[i]-48; } else if(x[i]>='A'&&x[i]<='F'){ b[i]=x[i]-55; } else{ b[i]=x[i]-87; } i++; } e=x.length(); i=0; while(i<x.length()){ y=pow(16,(e-i-1)); d=d+b[i]*y; i++; } cout<<d; return 0; }
-
0
#include <bits/stdc++.h>
using namespace std;
char a[16]={'1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g'};
int abb(char b){ b=tolower(b); for(int i=0;i<16;i++){ if(a[i]==b){ return i+1; } } }
int main() { char x; int n=0,m=0; while(cin>>x){ m=16*m+abb(x); } cout<<m; }
-
0
using namespace std; const int N=1000000; int c[N],p[N]; int main(){ char a; int b,g,h=0,e,x=0,y=0,m=0,q,s=0,v=0; while(cin>>a){ b=a; if(b>='0'&&b<='9'){ g=b-48; c[h]=g; h++; } else if(b>='A'&&b<='F'){ g=b-55; c[h]=g; h++; } } for(int u=h-1;u>=0;u--){ y+=c[u]*pow(16,m); m++; } while(y>0){ q=y%2; p[s]=q; s++; y=y/2; } for(int k=s-1;k>=0;--k){ v++; } if(v%4==0){ for(int k=s-1;k>=0;--k){ cout<<p[k]; } return 0; } else if(v%4!=0){ while(v%4!=0){ cout<<"0"; v++; } for(int k=s-1;k>=0;--k){ cout<<p[k]; } return 0; } }
-
0
using namespace std; int main(){ string a;int b,s=0,len; cin>>a; len=a.length(); for(b=0;b<=len;b++){ //length-b-1=读入数的次方 if(a[b]=='a' || a[b]=='A'){ s+=pow(16,(len-b-1))*10; } else if(a[b]=='b' || a[b]=='B'){ s+=pow(16,(len-b-1))*11; } else if(a[b]=='c' || a[b]=='C'){ s+=pow(16,(len-b-1))*12; } else if(a[b]=='d' || a[b]=='D'){ s+=pow(16,(len-b-1))*13; } else if(a[b]=='e' || a[b]=='E'){ s+=pow(16,(len-b-1))*14; } else if(a[b]=='f' || a[b]=='F'){ s+=pow(16,(len-b-1))*15; } else{ s+=pow(16,(len-b-1))*(a[b]-'0'); } } cout<<s+3; //我也不道为嘛加3,反正过咧 }
-
0
#include<bits/stdc++.h> using namespace std; int main() { int i=0,sum=0; char a,b[100000]; while(cin>>a) { i++; if(a=='a'||a=='A')a=10; else if(a=='b'||a=='B')a=11; else if(a=='c'||a=='C')a=12; else if(a=='d'||a=='D')a=13; else if(a=='e'||a=='E')a=14; else if(a=='f'||a=='F')a=15; else a-='0'; b[i]=a; } for(int j=i,k=0;j>=0;j--,k++)sum+=pow(16,k)*b[j]; cout<<sum; }
- 1
信息
- ID
- 60
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 5
- 标签
- 递交数
- 592
- 已通过
- 245
- 上传者