ZOJ 1205 Martian Addition
题目大意:大数,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的更多相关文章
- ZOJ Problem Set - 1205 Martian Addition
一道简单题,简单的20进制加减法,我这里代码写的不够优美,还是可以有所改进,不过简单题懒得改了... #include <stdio.h> #include <string.h> ...
- [ACM] ZOJ Martian Addition (20进制的两个大数相加)
Martian Addition Time Limit: 2 Seconds Memory Limit: 65536 KB In the 22nd Century, scientists ...
- ZOJ Martian Addition
Description In the 22nd Century, scientists have discovered intelligent residents live on the Mars. ...
- Martian Addition
In the 22nd Century, scientists have discovered intelligent residents live on the Mars. Martians are ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- C++解题报告 : 迭代加深搜索之 ZOJ 1937 Addition Chains
此题不难,主要思路便是IDDFS(迭代加深搜索),关键在于优化. 一个IDDFS的简单介绍,没有了解的同学可以看看: https://www.cnblogs.com/MisakaMKT/article ...
- [zoj] 1937 [poj] 2248 Addition Chains || ID-DFS
原题 给出数n,求出1......n 一串数,其中每个数字分解的两个加数都在这个序列中(除了1,两个加数可以相同),要求这个序列最短. ++m,dfs得到即可.并且事实上不需要提前打好表,直接输出就可 ...
- ZOJ题目分类
ZOJ题目分类初学者题: 1001 1037 1048 1049 1051 1067 1115 1151 1201 1205 1216 1240 1241 1242 1251 1292 1331 13 ...
随机推荐
- bzoj 2242: [SDOI2011]计算器
#include<cstdio> #include<iostream> #include<map> #include<cmath> #define ll ...
- LA 5061 LCA tarjan 算法
题目大意: 给定所有点的权值都为0,给定一棵树以后,每次询问都要求给定两点 x , y 和一个权值w,要求x,y路径上所有点权值加上w,最后求出每一个节点的值 这里因为查询和点都特别多,所以希望能最后 ...
- KStar ----BPM应用框架,K2 的新星
“KStar”是基于K2 BPM搭建的应用框架产品,将K2最佳实践方案以产品的形式呈现给用户,该框架面向SOA服务,便于二次开发和扩展,流程设计.用户组织.业务表单.流程管理.系统集成等开发工作,都按 ...
- as3基础知识
在AS3中,值类型数据(简单类型:Boolean.int.Number.String.uint)和引用类型数据(复杂类型)都是 对象,所以这两种类型对象存储的都是引用.但是,对应值类型数据,是一种不变 ...
- OpenCV坐标体系的初步认识
实验基础 本次实验通过一个简短的例子,主要来说明下面4个问题: 1. 坐标体系中的零点坐标为图片的左上角,X轴为图像矩形的上面那条水平线:Y轴为图像矩形左边的那条垂直线.该坐标体系在诸如结构体Mat, ...
- 创建和运行shell脚本程序
转载请标明http://www.cnblogs.com/winifred-tang94/ 要创建一个shell脚本程序,首先新建一个文本文件,然后在这个文本文件中按照shell编程规则输入shell命 ...
- @ResultMapping注解
@RequestMapping注解1.url映射放在方法上:@RequestMapping("/itemsEdit")2.窄化url请求映射放在类上,定义根路径,url就变成根路径 ...
- zookeeper启动失败无法查看status-----用户权限
最近一直在调试zookeeper,总是出现莫名其妙的问题 QuorumPeerMain 进程存在,但是无法查看status, JMX enabled by defaultUsing config: / ...
- 关于Mapper、Reducer的个人总结(转)
Mapper的处理过程: 1.1. InputFormat 产生 InputSplit,并且调用RecordReader将这些逻辑单元(InputSplit)转化为map task的输入.其中Inpu ...
- 【LeetCode OJ】Valid Palindrome
Problem Link: http://oj.leetcode.com/problems/valid-palindrome/ The following two conditions would s ...