zoj 1205 Martian Addition
来源:互联网 发布:制作婚礼视频软件 编辑:程序博客网 时间:2024/05/22 10:43
In the 22nd Century, scientists have discovered intelligent residents live on the Mars. Martians are very fond of mathematics. Every year, they would hold an Arithmetic Contest on Mars (ACM). The task of the contest is to calculate the sum of two 100-digit numbers, and the winner is the one who uses least time. This year they also invite people on Earth to join the contest.
As the only delegate of Earth, you're sent to Mars to demonstrate the power of mankind. Fortunately you have taken your laptop computer with you which can help you do the job quickly. Now the remaining problem is only to write a short program to calculate the sum of 2 given numbers. However, before you begin to program, you remember that the Martians use a 20-based number system as they usually have 20 fingers.
Input:
You're given several pairs of Martian numbers, each number on a line.
Martian number consists of digits from 0 to 9, and lower case letters from a to j (lower case letters starting from a to present 10, 11, ..., 19).
The length of the given number is never greater than 100.
Output:
For each pair of numbers, write the sum of the 2 numbers in a single line.
Sample Input:
1234567890abcdefghij99999jjjjj9999900001
Sample Output:
bdfi02467jiiiij00000
水体,复习一下大数
#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<fstream>#include<vector>#include<string>using namespace std;const int MAX=0xfffffff;typedef long long LL;const int maxx=110;void add(char *s1,char *s2){ int i,j,a[maxx+10]={0},b[maxx+10]={0}; int l1=strlen(s1); int l2=strlen(s2); for(i=l1-1,j=maxx;i>=0;i--,j--) { if(s1[i]>='0'&&s1[i]<='9') a[j]=s1[i]-'0'; else a[j]=s1[i]-'a'+10; } for(i=l2-1,j=maxx;i>=0;i--,j--) { if(s2[i]>='0'&&s2[i]<='9') b[j]=s2[i]-'0'; else b[j]=s2[i]-'a'+10; } for(i=maxx;i>=0;i--) { a[i]+=b[i]; if(a[i]>=20) a[i-1]+=a[i]/20,a[i]%=20; } int temp=0; for(i=0;i<=maxx;i++) { if(a[i]!=0 && temp==0) temp=1; if(temp==1) { if(a[i]<10) printf("%d",a[i]); else printf("%c",a[i]+'a'-10); } } if(temp==0) cout<<"0"; cout<<endl;}int main( ){ //freopen("1.txt","r",stdin); char a[110],b[110]; while(scanf("%s%s",a,b)!=EOF) add(a,b); return 0;}
0 0
- ZOJ 1205 Martian Addition
- zoj 1205 Martian Addition
- zoj 1205 Martian Addition
- ZOJ 1205 Martian Addition
- ZOJ 1205 Martian Addition
- ZOJ 1205 Martian Addition
- zoj 1205 Martian Addition
- ZOJ 1205 Martian Addition
- ZOJ 1205: Martian Addition
- ZOJ 1205 Martian Addition
- zoj 1205 Martian Addition
- Solution of ZOJ 1205 Martian Addition
- ZOJ Problem Set - 1205 Martian Addition
- zoj 1205.Martian Addition
- ZOJ 1205 Martian Addition (20进制加法)
- Martian Addition
- fjnu 1865 Martian Addition
- 【ACM】Martian Addition
- vi命令大全
- 来点基础的--诡异的极客们的符号--流、管道和文件的耦合
- Yii中的PHPExcel解决办法
- hihocoder:无间道之并查集
- 近期学习计划
- zoj 1205 Martian Addition
- 用cocos2d-x 3.2 实现的FlappyBird
- arduino实现tts
- 苹果开发之路——简述
- 简单整数算术运算
- 类和对象第一讲
- 四大发送到发送到
- 消息队列的介绍和原理
- How to improve Java's I/O performance( 提升 java i/o 性能)