Izhx's submissions
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64
Description
As one of the most powerful brushes, zhx submits a lot of code on many oj and most of them got AC.
One day, zhx wants to count how many submissions he made on $n$ ojs. He knows that on the $i^{th}$ oj, he made $a_i$ submissions. And what you should do is to add them up.
To make the problem more complex, zhx gives you $n$ $B-base$ numbers and you should also return a $B-base$ number to him.
What's more, zhx is so naive that he doesn't carry a number while adding. That means, his answer to $5 + 6$ in $10-base$ is $1$. And he also asked you to calculate in his way.
One day, zhx wants to count how many submissions he made on $n$ ojs. He knows that on the $i^{th}$ oj, he made $a_i$ submissions. And what you should do is to add them up.
To make the problem more complex, zhx gives you $n$ $B-base$ numbers and you should also return a $B-base$ number to him.
What's more, zhx is so naive that he doesn't carry a number while adding. That means, his answer to $5 + 6$ in $10-base$ is $1$. And he also asked you to calculate in his way.
Input
Multiply test cases(less than $1000$). Seek $EOF$ as the end of the file.
For each test, there are two integers $n$ and $B$ separated by a space. ($1 \leq n \leq 100$, $2 \leq B \leq 36$)
Then come n lines. In each line there is a $B-base$ number(may contain leading zeros). The digits are from $0$ to $9$ then from $a$ to $z$(lowercase). The length of a number will not execeed 200.
For each test, there are two integers $n$ and $B$ separated by a space. ($1 \leq n \leq 100$, $2 \leq B \leq 36$)
Then come n lines. In each line there is a $B-base$ number(may contain leading zeros). The digits are from $0$ to $9$ then from $a$ to $z$(lowercase). The length of a number will not execeed 200.
Output
For each test case, output a single line indicating the answer in $B-base$(no leading zero).
Sample Input
2 3 2 2 1 4 233 3 16 ab bc cd
Sample Output
1 233 14该题是大数加法的模拟题, 最主要的wa点是在那个0 输入0 是输出0~~#include<stdio.h> #include<string.h> int main() { int n,m,k,maxl,flag,t,i,j; char a[300][300]; int s[300]; while(~scanf("%d%d",&n,&m)) { memset(s,0,sizeof(s)); maxl=flag=t=0; for(i=0;i<n;i++) { scanf("%s",a[i]); } for(i=0;i<n;i++) { k=0; int l=strlen(a[i]); if(l>maxl) maxl=l; for(j=l-1;j>=0;j--) //k变量控制0 的输入和输出 { if(a[i][j]>='0'&&a[i][j]<='9') { s[k]+=a[i][j]-'0'; s[k]%=m; } else if(a[i][j]>='a'&&a[i][j]<='z') { s[k]+=a[i][j]+10-'a'; s[k]%=m; } k++; } } for(i=maxl-1;i>=0;i--) //输出 { if(s[i]==0&&flag==0) { t++; } else { flag=1; if(s[i]>=0&&s[i]<=9) printf("%d",s[i]); else printf("%c",s[i]-10+'a'); } } if(t==maxl) printf("0\n"); //输入0 输出0 else printf("\n"); } return 0; }