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 ...
随机推荐
- POJ 2253 Frogger 最短路 难度:0
http://poj.org/problem?id=2253 #include <iostream> #include <queue> #include <cmath&g ...
- js字符转换成整型 parseInt()函数规程Number()函数
今天在做一个js加法的时候,忘记将字符转换成整型,导致将加号认为是连接符, 在运算前要先对字符井行类型转换,使用parseInt()函数 使用Number()将字符转换成int型效果更好
- 线程系列4---sleep()和wait()方法区别
2013-12-25 14:49:00 1. sleep()方法是Thread类的一个静态方法,可以在任意地方被调用,而wait()方法是object类的一个方法,只能在同步代码块或者同步方法里面,通 ...
- 2、IValueConverter应用
1.C#代码如下: public class logotoimgConverter:IValueConverter { //将logo转换为URI public object Convert(obje ...
- 一台服务器搭载两个tomcat项目
之前下载的mysql 在官网是有 历史库的 如果现在一台机器上已经部署了一个tomcat服务,无论这个tomcat是否已经注册为服务了,或者没有注册windows服务,或者注册了,都没关系.都可以采 ...
- Xutils的使用 转载 带自己细细研究
单例模式static DbUtils db = null; public static DbUtils getDb(Context context) { if (context == null) { ...
- flash 和 第三方程序交互
一.flash 端 修改 1.flash cs6 修改脚本 为as3 2.修改 按钮 实例 名 (不是sprite列表中的名字 实例名称 和这个名字 是2个) 3.时间轴上 添加代码 当前选择 A ...
- java基础-004
---恢复内容开始--- 14.Java集合类框架的基本接口 集合类接口指定了一组叫做元素的对象.集合类接口的每一种具体的实现类都可以选择以它自己的方式对元素进行保存和排序.有的集合类允许重复的键,有 ...
- 在iis6.0公布asp.net mvc3网站
在iis6.0发布asp.net mvc3网站 这个问题一直困扰了我很长一段时间,终于在今天综合网上查的资料把它解决了. 在iis6.0发布asp.net mvc3网站 1 需要在服务器下安装.n ...
- poj1159 dp最长公共子串
//Accepted 204 KB 891 ms //dp最长公共子串 //dp[i][j]=max(dp[i-1][j],dp[i][j-1]) //dp[i][j]=max(dp[i][j],dp ...