Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
//bestcoder#33_1001 #include<iostream> #include<stdio.h> #include<string.h> #include<ctype.h> using namespace std; const int maxn=210; const int INF=(1<<28); int n,B; int a[maxn]; char str[maxn]; //数组定义是需要时间的,因此在循环多次时尽量避免定义在循环里 int getnum(char ch) { if(ch<=‘9‘&&ch>=‘0‘) return ch-‘0‘; return ch-‘a‘+10; } int main() { while(scanf("%d%d",&n,&B)!=EOF){ memset(a,0,sizeof(a)); while(n--){ scanf("%s",str); int len=strlen(str); for(int i=0;i<len;i++){ a[i]=(a[i]+getnum(str[len-1-i]))%B; //按题意模拟,转成整数进行高精度运算 } } int len=maxn; while(a[len-1]==0&&len>1) len--; //去前导0 for(int i=len-1;i>=0;i--){ //输出 if(a[i]<=9) printf("%c",(char)(a[i]+‘0‘)); else printf("%c",(char)(a[i]-10+‘a‘)); } printf("\n"); } return 0; }
原文:http://www.cnblogs.com/--560/p/4338600.html