什么进制星球?

P1604 B进制星球

我的代码更好理解 ```cpp #include<cstdio> #include<string> #include<iostream> using namespace std; int K; string twosum(string a,string b) { string c; int carry=0,three; for(int i=a.size()-1,j=b.size()-1;i>=0||j>=0;i--,j--) { int first= i>=0? a[i]-'0':0; int second= j>=0? b[j]-'0':0; three=(first+second+carry)%K; carry=(first+second+carry)/K; c.insert(c.begin(),three+'0'); } if(carry) c.insert(c.begin(),carry+'0'); return c; } int main() { string a,b; int i; scanf("%d",&K); cin>>a>>b; for(i=0;i<a.size()||i<b.size();i++) { if(i<a.size()&&a[i]>='A') a[i]=a[i]-'A'+1+'9'; if(i<b.size()&&b[i]>='A') b[i]=b[i]-'A'+1+'9'; } string c=twosum(a,b); for(i=0;i<c.size();i++) { if(c[i]>'9') printf("%c",c[i]-'9'+'A'-1); else printf("%c",c[i]); } return 0; } ```
by resftlmuttmotw @ 2018-11-17 11:26:57


@[resftlmuttmotw](/space/show?uid=73992) 加点注释吧大佬
by A_Đark_Horcrux @ 2018-11-17 13:49:14


@[Bilion_冰凌帅](/space/show?uid=54372) 我认为我的代码不加注释也能被理解
by resftlmuttmotw @ 2018-11-17 14:00:58


@[resftlmuttmotw](/space/show?uid=73992) 那c.size(),c.insert,c.begin是什么啊
by A_Đark_Horcrux @ 2018-11-17 19:47:54


@[Bilion_冰凌帅](/space/show?uid=54372) string 这个类型 有很多自带的函数 c.szie() 返回其中c的字符数量 c.begin()返回的是一个指针(迭代器)指向c的第一个字符的前一个位置 c.insert(c.begin(),$$) 它的意思就是在c.begin()处插入$$
by resftlmuttmotw @ 2018-11-18 11:58:58


@[resftlmuttmotw](/space/show?uid=73992) OK谢谢大佬
by A_Đark_Horcrux @ 2018-11-18 12:54:15


%%%绿名大佬
by smallfang @ 2018-11-22 18:12:33


|