hdu 2106
来源:互联网 发布:大数据的真实性特点 编辑:程序博客网 时间:2024/05/19 18:43
Problem Description
As we know , we always use the decimal system in our common life, even using the computer. If we want to calculate the value that 3 plus 9, we just import 3 and 9.after calculation of computer, we will get the result of 12.
But after learning <<The Principle Of Computer>>,we know that the computer will do the calculation as the following steps:
1 computer change the 3 into binary formality like 11;
2 computer change the 9 into binary formality like 1001;
3 computer plus the two number and get the result 1100;
4 computer change the result into decimal formality like 12;
5 computer export the result;
In the computer system there are other formalities to deal with the number such as hexadecimal. Now I will give several number with a kind of change method, for example, if I give you 1011(2), it means 1011 is a number in the binary system, and 123(10) means 123 if a number in the decimal system. Now I will give you some numbers with any kind of system, you guys should tell me the sum of the number in the decimal system.
But after learning <<The Principle Of Computer>>,we know that the computer will do the calculation as the following steps:
1 computer change the 3 into binary formality like 11;
2 computer change the 9 into binary formality like 1001;
3 computer plus the two number and get the result 1100;
4 computer change the result into decimal formality like 12;
5 computer export the result;
In the computer system there are other formalities to deal with the number such as hexadecimal. Now I will give several number with a kind of change method, for example, if I give you 1011(2), it means 1011 is a number in the binary system, and 123(10) means 123 if a number in the decimal system. Now I will give you some numbers with any kind of system, you guys should tell me the sum of the number in the decimal system.
Input
There will be several cases. The first line of each case contains one integers N, and N means there will be N numbers to import, then there will be N numbers at the next N lines, each line contains a number with such form : X1….Xn.(Y), and 0<=Xi<Y, 1<Y<=10. I promise you that the sum will not exceed the 100000000, and there will be at most 100 cases and the 0<N<=1000.
Output
There is only one line output case for each input case, which is the sum of all the number. The sum must be expressed using the decimal system.
Sample Input
31(2)2(3)3(4)411(10)11(2)11(3)11(4)
Sample Output
623
Source
HDU 2007-6 Programming Contest
解题思路:
简单地字符串处理,将括号里面的进制数统计出来,然后在将括号前面的进制数转换成十进制数。
#include<stdio.h>#include<string.h>#include<math.h> int main() { int n; int i,j; char ss[110]; int len; int k,p,t,jinzhi; int sum; while(scanf("%d",&n)!=EOF) { memset(ss,0,sizeof(ss)); sum=0; for(i=0;i<n;i++) { scanf("%s",ss); len=strlen(ss); k=len-4; jinzhi=0; while(ss[k]!='(') k++; for(j=k+1;j<len-1;j++) { jinzhi=jinzhi*10+ss[j]-'0'; }p=k-1; for(j=p,t=0;j>=0;j--,t++) sum+=pow(jinzhi,t)*(ss[j]-'0'); } printf("%d\n",sum); } return 0; }
0 0
- hdu 2106
- hdu 2106
- hdu-2106
- hdu 2106
- hdu 2106
- hdu 2106
- HDU 2106 decimal system
- HDU 2106 decimal system
- HDU 2106 Decimal System
- hdu-2106-decimal system
- hdu 2106 decimal system
- decimal system hdu 2106
- hdu 2106 decimal system
- HDU 2106 decimal system
- hdu 2106 decimal system
- HDU 2106 decimal system
- HDU-2106(decimal system)
- hdu
- UVA 10910 Marks Distribution(组合数学 或 递推)
- 关于sdcard的理解
- opengl 贴图
- 三张图让你快速明白activity与fragment生命周期的异同点
- 柞滋捉罪足紫状兹淄祝籽篆综抓追罪驻茁
- hdu 2106
- 纂遵驻孜子资缀壮着琢紫尊滋驻注住资坠
- openwebglobe 简单功能实现 Virtual Earth (虚拟地球)demo
- Swing Substance笔记
- 卒字自自姿注纂紫阻纂琢卓捉紫走缀遵遵
- 中国现在开源系统cms 论坛排行榜
- c++5
- 互联网产品用户体验设计方法和用户体验优化方法
- ZOJ 3829 Known Notation