hdu 5186 zhx's submissions
来源:互联网 发布:大宗交易数据查询 编辑:程序博客网 时间:2024/05/22 06:52
zhx's submissions
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 648 Accepted Submission(s): 167
Problem DescriptionAs 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 ith oj, he made ai 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.
InputMultiply 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≤n≤100 , 2≤B≤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.
OutputFor each test case, output a single line indicating the answer in B−base (no leading zero).
Sample Input2 3221 42333 16abbccd
Sample Output123314
这个题有 好几个比较坑的地方,(1),,结果是0(2),,根据我的算法,注意s2>s1(长度上)的情况(3),,注意要给s1末尾加上\0#include<iostream>#include<math.h>#include<fstream>#include<cstring>#include<algorithm>using namespace std;typedef long long LL;char s1[220],s2[220];char s3[220];int b;void PRINT(char s[]){ bool flag=0; for(unsigned int i=0;i<strlen(s);i++) { if(s[i]=='0'&&flag==0) continue; else { flag=1; printf("%c",s[i]); } } if(flag==0) cout<<"0"; printf("\n");}void ADD(char s1[],char s2[]){ if(strlen(s1)>=strlen(s2)) for(int i=strlen(s1)-1,j=strlen(s2)-1;i>=0&&j>=0;i--,j--) { int t1=s1[i]>'9'?s1[i]-'a'+10:s1[i]-'0'; int t2=s2[j]>'9'?s2[j]-'a'+10:s2[j]-'0'; int t3=(t1+t2)%b; if(t3>9) s1[i]=t3-10+'a'; else s1[i]=t3+'0'; } else { for(int i=strlen(s1)-1,j=strlen(s2)-1;i>=0&&j>=0;i--,j--) { int t1=s1[i]>'9'?s1[i]-'a'+10:s1[i]-'0'; int t2=s2[j]>'9'?s2[j]-'a'+10:s2[j]-'0'; int t3=(t1+t2)%b; if(t3>9) s2[j]=t3-10+'a'; else s2[j]=t3+'0'; } for(int i=0;i<strlen(s2);i++) s1[i]=s2[i]; s1[strlen(s2)]='\0'; }}int main(){ //freopen("1.txt","r",stdin); int n; while(scanf("%d %d",&n,&b)!=EOF) { if(n==1) { scanf("%s",s1); PRINT(s1); } else { scanf("%s",s1); scanf("%s",s2); ADD(s1,s2); for(int i=3;i<=n;i++) { scanf("%s",s2); ADD(s1,s2); } PRINT(s1); } } return 0;}
One day, zhx wants to count how many submissions he made on
To make the problem more complex, zhx gives you
What's more, zhx is so naive that he doesn't carry a number while adding. That means, his answer to
For each test, there are two integers
Then come n lines. In each line there is a
2 3221 42333 16abbccd
123314
#include<iostream>#include<math.h>#include<fstream>#include<cstring>#include<algorithm>using namespace std;typedef long long LL;char s1[220],s2[220];char s3[220];int b;void PRINT(char s[]){ bool flag=0; for(unsigned int i=0;i<strlen(s);i++) { if(s[i]=='0'&&flag==0) continue; else { flag=1; printf("%c",s[i]); } } if(flag==0) cout<<"0"; printf("\n");}void ADD(char s1[],char s2[]){ if(strlen(s1)>=strlen(s2)) for(int i=strlen(s1)-1,j=strlen(s2)-1;i>=0&&j>=0;i--,j--) { int t1=s1[i]>'9'?s1[i]-'a'+10:s1[i]-'0'; int t2=s2[j]>'9'?s2[j]-'a'+10:s2[j]-'0'; int t3=(t1+t2)%b; if(t3>9) s1[i]=t3-10+'a'; else s1[i]=t3+'0'; } else { for(int i=strlen(s1)-1,j=strlen(s2)-1;i>=0&&j>=0;i--,j--) { int t1=s1[i]>'9'?s1[i]-'a'+10:s1[i]-'0'; int t2=s2[j]>'9'?s2[j]-'a'+10:s2[j]-'0'; int t3=(t1+t2)%b; if(t3>9) s2[j]=t3-10+'a'; else s2[j]=t3+'0'; } for(int i=0;i<strlen(s2);i++) s1[i]=s2[i]; s1[strlen(s2)]='\0'; }}int main(){ //freopen("1.txt","r",stdin); int n; while(scanf("%d %d",&n,&b)!=EOF) { if(n==1) { scanf("%s",s1); PRINT(s1); } else { scanf("%s",s1); scanf("%s",s2); ADD(s1,s2); for(int i=3;i<=n;i++) { scanf("%s",s2); ADD(s1,s2); } PRINT(s1); } } return 0;}
0 0
- hdu 5186 zhx's submissions
- HDU - 5186 zhx's submissions
- hdu 5186 zhx's submissions
- hdu 5186 zhx's submissions(模拟)
- HDU 5186 zhx's submissions (进制转换)
- HDU - 5186 - zhx's submissions (大数高精度)
- HDU 5186 zhx's submissions 模拟水题
- HDU-5186-zhx's submissions(Java+简单模拟)
- 杭电 HDU ACM 5186 zhx's submissions
- hdu 5186 zhx's submissions 5187 zhx's contest快速幂小优化
- hdu5186 zhx's submissions
- 【CUGBACM15级BC第33场 A】hdu 5186 zhx's submissions
- BestCoder #33 zhx's submissions
- BestCoder Round #33 1001 zhx's submissions
- zhx's contest HDU
- HDU 5187 zhx's contest
- HDU - 5187 zhx's contest
- hdu 5187-zhx's contest
- 如何在win7下安装XP系统?
- Hadoop 配置及hadoop HA 的配置
- 启动Tomcat提示:指定的服务未安装
- 函数的增长
- path和classpath环境变量的配置目的及其配置的必要性说明
- hdu 5186 zhx's submissions
- 在Ubuntu 14.04 64bit下用Python搭建数据科学研究环境
- URAL 1725. Sold Out!(数学啊 )
- 猜拳小游戏 C语言
- eclipse+cdt+mingw配置。
- CSDN-Markdown编辑器之UML序列图
- typedef四用途与两陷阱
- [Leetcode] 39. Combination Sum
- 【Android基础】多媒体编程部分总结