原题链接

题目大意:大数,20进制的加法计算。

解法:convert函数把字符串转换成数组,add函数把两个大数相加。

参考代码:

#include<stdio.h>
#include<string.h> char* Digit="0123456789abcdefghij";
void convert(char*,int*);
void add(int*,int*,int*);
void print(int*);
int main(){
char str1[101],str2[101];
while(scanf("%s",str1)!=EOF&&scanf("%s",str2)!=EOF){
int num1[101]={0},num2[101]={0},num3[102]={0};
convert(str1,num1);
convert(str2,num2);
add(num1,num2,num3);
print(num3);
} return 0;
} void convert(char* str, int* num){
int j,k;
k=0;
for(j=strlen(str)-1;j>=0;j--){
if(str[j]<='9'&&str[j]>='0')
num[k]=str[j]-'0';
if(str[j]<='j'&&str[j]>='a')
num[k]=str[j]-'W';
k++;
}
}
void add(int* num1, int* num2, int* num3){
int i,j=101,add=0,c=0;
for(i=0;i<101;i++){
add=num1[i]+num2[i]+c;
c=add/20;
num3[j]=add%20;
j--;
}
if(c==1)
num3[j]=1;
}
void print(int* num){
int i,j=0;
while(num[j]==0)j++;
if(j>101){
printf("0\n");
}
else{
for(;j<102;j++){
printf("%c",Digit[num[j]]);
}
printf("\n");
}
}

ZOJ 1205 Martian Addition的更多相关文章

  1. ZOJ Problem Set - 1205 Martian Addition

    一道简单题,简单的20进制加减法,我这里代码写的不够优美,还是可以有所改进,不过简单题懒得改了... #include <stdio.h> #include <string.h> ...

  2. [ACM] ZOJ Martian Addition (20进制的两个大数相加)

    Martian Addition Time Limit: 2 Seconds      Memory Limit: 65536 KB   In the 22nd Century, scientists ...

  3. ZOJ Martian Addition

    Description In the 22nd Century, scientists have discovered intelligent residents live on the Mars. ...

  4. Martian Addition

    In the 22nd Century, scientists have discovered intelligent residents live on the Mars. Martians are ...

  5. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  6. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  7. C++解题报告 : 迭代加深搜索之 ZOJ 1937 Addition Chains

    此题不难,主要思路便是IDDFS(迭代加深搜索),关键在于优化. 一个IDDFS的简单介绍,没有了解的同学可以看看: https://www.cnblogs.com/MisakaMKT/article ...

  8. [zoj] 1937 [poj] 2248 Addition Chains || ID-DFS

    原题 给出数n,求出1......n 一串数,其中每个数字分解的两个加数都在这个序列中(除了1,两个加数可以相同),要求这个序列最短. ++m,dfs得到即可.并且事实上不需要提前打好表,直接输出就可 ...

  9. ZOJ题目分类

    ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...

随机推荐

  1. STM32-AFIO

    只有使用了AFIO的事件控制寄存器.AFIO的重映射功能以及外部中断(EXTI)控制寄存器才需要开启AFIO的时钟,STM32参考手册从来没说过使用IO的复用功能就一定要开启AFIO时钟,这是个误区.

  2. C++-什么时候需要在类的构造函数中使用初始化列表

    1,如果基类没有default构造函数,则意味着其不能自己初始化.如果其被派生,派生类的构造函数要负责调用基类的构造函数,并传递给它需要的参数.下例中Base 2,如果类成员没有默认构造函数.下例中E ...

  3. K2十年:专注BPM

    <聚·谋·变——K2中国用户大会> 导演:K2中国 主演:K2用户 时长:420分钟 票价:免费 上映日期:2015年7月17日 查看完整视频请关注K2官方微信账号

  4. CSS引入外部字体

    @font-face {    font-family: '综艺体';    font-style: normal;    font-weight: normal;    src: url(../cs ...

  5. A380上11万一张的机票什么享受?来看看

    上个月底,全球奢华航班排行榜出炉,新加坡航空头等舱荣登第一.不过,比头等舱更豪奢的,将近两万美元一张往返票的“套间”又是怎么样的呢? 新加坡航空的一名常旅客Derek Low就体验了一把全球最豪奢的坐 ...

  6. ld can't link with a main executable file for architecture armv7

    在iPhone 6 Plus上跑的时候遇到了这么一个错误:ld can't link with a main executable file for architecture armv7,然后就各种改 ...

  7. stm32的软件架构问题

    1. 架构组成:程序代码分为四种结构a) 顺序执行代码定义:按照顺序逐行执行的代码优点:是思路简单,代码可靠不易被干扰.缺点:占用资源用途:只用来各种变量.函数的定义,硬件的初始化程序位置:main. ...

  8. hdu 2080

    ps:水题...求夹角...先求出COS,然后用acos 代码: #include "stdio.h" #include "math.h" int main() ...

  9. 无线安全渗透测试套件WiFi-Pumpkin新版本发布

    WiFi-Pumpkin是一款无线安全检测工具,利用该工具可以伪造接入点完成中间人攻击,同时也支持一些其它的无线渗透功能.旨在提供更安全的无线网络服务,该工具可用来监听目标的流量数据,通过无线钓鱼的方 ...

  10. 3、SQL基础整理(分组)

    分组 group by select class from xuesheng group by class select class,AVG(chinese)from xuesheng group b ...