ZOJ 1205 Martian Addition (20进制加法)
来源:互联网 发布:mac怎么把图标放到桌面 编辑:程序博客网 时间:2024/05/16 11:19
Martian Addition
时间限制(普通/Java):2000MS/3000MS 运行内存限制:65536KByte
总提交:15 测试通过:7
描述
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.
输入
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.
输出
For each pair of numbers, write the sum of the 2 numbers in a single line.
样例输入
1234567890
abcdefghij
99999jjjjj
9999900001
样例输出
bdfi02467j
iiiij00000
解题思路:设和sum=0 ,先将sum = sum + a, 再将 sum = sum + b;
#include <iostream>#include <cstring>using namespace std;char a[101], b[101];int sum[200];int main() {int len1, len2, i, j, t;while (cin>>a>>b){memset(sum, 0, sizeof(sum));len1 = strlen(a);len2 = strlen(b);for (i=len1-1,j=199; i>=0; i--, j--){ if (a[i]>='a') //判断是的否大于10t = sum[j] + a[i] - 87;elset = sum[j] + a[i] - '0';sum[j] = t % 20;sum[j-1] = t / 20;}for (i=len2-1,j=199; i>=0; i--, j--){ if (b[i]>='a')t = sum[j] + b[i] - 87;else t = sum[j] + b[i] - '0';sum[j] = t % 20;sum[j-1] += t / 20 ;}i = 0;while (sum[i]==0) i++;for (i; i<200; i++){if (sum[i]<=9)cout<<sum[i];else cout<<char(sum[i]+87); //如果大于9,进行转换}cout<<endl;}return 0;}
- ZOJ 1205 Martian Addition (20进制加法)
- 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
- [ACM] ZOJ Martian Addition (20进制的两个大数相加)
- Solution of ZOJ 1205 Martian Addition
- ZOJ Problem Set - 1205 Martian Addition
- zoj 1205.Martian Addition
- Martian Addition
- fjnu 1865 Martian Addition
- 润乾填报报表实现非图片文件上传下载
- Flex 通过FABridge与JS交互
- 标准C++以及MFC6.0字符串的tokenize和split函数
- PHP+MySQL+Apache 配置
- Struts 2 避免表单重复提交
- ZOJ 1205 Martian Addition (20进制加法)
- 2013暑假总结
- java_web学习第二天(ServletConfig和ServletContext对象的作用和使用)
- C#如何动态生成treeview节点
- Liferay 持久层
- windows压缩、备份文件
- java经典实例分析
- asp.net 母版页使用详解
- JAVA的面向对象编程高手笔记