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 2143: 飞飞侠
#include<cstdio> #include<iostream> #include<queue> #define inf 1000000000 #define ...
- bzoj 1816: [Cqoi2010]扑克牌
#include<cstdio> #include<iostream> using namespace std; ],ans; bool pan(int x) { int a1 ...
- 反质数(Antiprimes)
转载http://www.cnblogs.com/tiankonguse/archive/2012/07/29/2613877.html 问题描述: 对于任何正整数x,起约数的个数记做g(x).例如g ...
- mysql给定一个随机数
)) 给定一个1-50中间的随机数
- 【codevs1036】商务旅行 LCA 倍增
1036 商务旅行 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 某首都城市的商人要经常到各城镇去做生意,他们按自己的 ...
- DB2配置信息查看及其更新命令
获取DB2配置信息 db2 get dbm cfg 更新DB2链接配置信息 db2 update dbm cfg using authentication server db2stop db2star ...
- 踏着前人的脚印学Hadoop——结构、重点
HDFS作为一个分布式文件系统,是所有这些项目的基础.分析好HDFS,有利于了解其他系统.由于Hadoop的HDFS和MapReduce是同一个项目,我们就把他们放在一块,进行分析. 如果把整个had ...
- Android文件Apk下载变ZIP压缩包
在azure云存储中 上传apk文件 使用ie下载 变成zip压缩包 解决方法 编辑 blob 属性和元数据 修改 内容类型 为 application/vnd.android.package-arc ...
- C# IList<T>转为DataTable
public class WebUtil { /// <summary> /// 转换IList<T>为DataTable/// </summary> /// &l ...
- JS 原型继承的几种方法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...