ZOJ Martian Addition
Description
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
1234567890
abcdefghij
99999jjjjj
9999900001
Sample Output
bdfi02467j
iiiij00000
- #include<iostream>
- #include<stdio.h>
- #include<cstring>
- #include<algorithm>
- using namespace std;
- char a[],b[];
- int r[];
- int s(char d)
- {
- if(d>=''&&d<='')
- return d-'';
- else if(d>='a'&&d<='j')
- return d-'a'+;
- }
- char q(int i)
- {
- if(i>=&&i<=)
- return ''+i;
- else if(i>=&&i<=)
- return 'a'+i-;
- }
- int main()
- {
- int len1,len2,len3;
- int i,j;
- char c;
- while(cin>>a>>b)
- {
- len1=strlen(a);
- len2=strlen(b);
- memset(r,,sizeof(r));
- for(i=;i<len1/;i++)
- {
- c=a[i];
- a[i]=a[len1--i];
- a[len1--i]=c;
- }
- for(i=;i<len2/;i++)
- {
- c=b[i];
- b[i]=b[len2--i];
- b[len2--i]=c;
- }
- for(i=;i<min(len1,len2);i++)
- {
- r[i]=s(a[i])+s(b[i]);
- }
- for(i=min(len1,len2);i<max(len1,len2);i++)
- {
- if(len1>len2)
- r[i]=s(a[i]);
- else
- r[i]=s(b[i]);
- }
- len3=i;
- for(i=;i<len3;i++)
- {
- if(r[i]>=)
- {
- r[i+]++;
- r[i]-=;
- }
- }
- if(r[len3]!=)
- len3++;
- for(i=len3-;i>=;i--)
- cout<<q(r[i]);
- cout<<endl;
- }
- return ;
- }
ZOJ Martian Addition的更多相关文章
- [ACM] ZOJ Martian Addition (20进制的两个大数相加)
Martian Addition Time Limit: 2 Seconds Memory Limit: 65536 KB In the 22nd Century, scientists ...
- ZOJ Problem Set - 1205 Martian Addition
一道简单题,简单的20进制加减法,我这里代码写的不够优美,还是可以有所改进,不过简单题懒得改了... #include <stdio.h> #include <string.h> ...
- ZOJ 1205 Martian Addition
原题链接 题目大意:大数,20进制的加法计算. 解法:convert函数把字符串转换成数组,add函数把两个大数相加. 参考代码: #include<stdio.h> #include&l ...
- Martian Addition
In the 22nd Century, scientists have discovered intelligent residents live on the Mars. Martians are ...
- C++解题报告 : 迭代加深搜索之 ZOJ 1937 Addition Chains
此题不难,主要思路便是IDDFS(迭代加深搜索),关键在于优化. 一个IDDFS的简单介绍,没有了解的同学可以看看: https://www.cnblogs.com/MisakaMKT/article ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- [zoj] 1937 [poj] 2248 Addition Chains || ID-DFS
原题 给出数n,求出1......n 一串数,其中每个数字分解的两个加数都在这个序列中(除了1,两个加数可以相同),要求这个序列最短. ++m,dfs得到即可.并且事实上不需要提前打好表,直接输出就可 ...
- 详解OJ(Online Judge)中PHP代码的提交方法及要点【举例:ZOJ 1001 (A + B Problem)】
详解OJ(Online Judge)中PHP代码的提交方法及要点 Introduction of How to submit PHP code to Online Judge Systems Int ...
随机推荐
- 使用spring-data-mongodb操作mongodb
mongodb.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="h ...
- Access一些常用的SQL语句
您可以将 Microsoft Office Access 2013 用作创建.修改数据库以及处理数据的工具,还可将 Office Access 2013 用作服务器数据库管理系统(如 Microsof ...
- (一)Harbor安装 -- 企业级Registry仓库
根据Harbor官方描述: Harbor是一个用于存储和分发Docker镜像的企业级Registry服务器,通过添加一些企业必需的功能特性,例如安全.标识和管理等,扩展了开源Docker Distri ...
- trove显示更多flavor信息
https://review.openstack.org/#/c/352786/12 这是我目前提交的commit,如果想添加新的flavor信息可以参考这个,有几个需要注意的点是在跑py27的时候, ...
- 研究表明,VR社交有助于内向者改变性格
目前,外界对于VR的普遍观点是这种头显提供了一种孤立的.反社会性的体验.但很少有人会意识到,虚拟现实同时也存在着能够增进人与人之间的关系的可能性. Facebook(脸书)IQ是人们连接这一社交网络的 ...
- maven项目如何引用本地的jar包
下载该jar包到本地(如下载目录结构为:D:\Users\lu.wang\Downloads\searchservice\searchservice\jar\ttd.search.searchserv ...
- bat脚本-set(setlocal enabledelayedexpansion) 学习
设置本地为延迟扩展.其实也就是:延迟变量,全称延迟环境变量扩展. 事件一: @echo off set a=4 set a=5&echo %a% pause 解说:为什么是4而不是5呢?在ec ...
- PAT乙级1004. 成绩排名 (20)
读入n名学生的姓名.学号.成绩,分别输出成绩最高和成绩最低学生的姓名和学号. 输入格式:每个测试输入包含1个测试用例,格式为 第1行:正整数n 第2行:第1个学生的姓名 学号 成绩 第3行:第2个学生 ...
- spring 加载多个资源文件
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.Prop ...
- 如果有两个list<Object>只取出两个中不重复的(还可以优化,这里计数器没做好,暂时使用第三变量)
import java.util.*; class test2{ public static void main(String[] args){ List<Integer> objList ...