原题链接

题目大意:大数,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. UVa 10253 - Series-Parallel Networks

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  2. 跨域SSO的实现

    翻译自CodeProject网站ASP.NET9月份最佳文章:Single Sign On (SSO) for cross-domain ASP.NET applications. 翻译不妥之处还望大 ...

  3. java udp网络编程

    import java.net.*; /* 通过UDP传输发送文字数据 1.建立socket服务 2.提供数据,并封装到数据包中 3.通过sokect服务的发送功能,将数据包发送出去 4.关闭资源 * ...

  4. IBM RSA 的语言设置

    右键 IBM Rational software Architect for websphere software 快捷方式 ----> 打开文件位置 在 eclipse.ini 文件中添加参数 ...

  5. hibernate缓存和提高效率

    1.使用二级缓存,多把大批量的.短期多次的查询数据存到二级缓存中,避免和数据库的多次交互,增加负担.二级缓存加在那些增删改少的,查询多的类中.二级缓存的是对象,如果查出来的不是对象,不会放到缓存中去. ...

  6. Android高薪之路-Android程序员面试宝典

    Android高薪之路-Android程序员面试宝典

  7. PHP数据类型和常量

    数据类型的转换    一种是强制转换            语法:setType(变量,类型).这个函数将原变量的类型转变                在赋值前使用(类型)的形式,不会改变原变量的类 ...

  8. ERP联系记录管理(十七)

    联系记录管理修改页面: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Co ...

  9. Spring处理器

    Spring容器内部工作机制 Spring的AbstractApplicationContext是ApplicationContext抽象实现类,该抽象类的refresh()方法定义了Spring容器 ...

  10. Cocos2d-x 3.x项目创建

    1.首先打开终端,cd到cocos2d-x-3.2目录下,运行命令./setup.py 2. 首先,打开终端cd到目录/cocos2d-x-3.2/tools/cocos2d-console/bin下 ...