原题链接

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

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

参考代码:

  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. char* Digit="0123456789abcdefghij";
  5. void convert(char*,int*);
  6. void add(int*,int*,int*);
  7. void print(int*);
  8. int main(){
  9. char str1[101],str2[101];
  10. while(scanf("%s",str1)!=EOF&&scanf("%s",str2)!=EOF){
  11. int num1[101]={0},num2[101]={0},num3[102]={0};
  12. convert(str1,num1);
  13. convert(str2,num2);
  14. add(num1,num2,num3);
  15. print(num3);
  16. }
  17.  
  18. return 0;
  19. }
  20.  
  21. void convert(char* str, int* num){
  22. int j,k;
  23. k=0;
  24. for(j=strlen(str)-1;j>=0;j--){
  25. if(str[j]<='9'&&str[j]>='0')
  26. num[k]=str[j]-'0';
  27. if(str[j]<='j'&&str[j]>='a')
  28. num[k]=str[j]-'W';
  29. k++;
  30. }
  31. }
  32. void add(int* num1, int* num2, int* num3){
  33. int i,j=101,add=0,c=0;
  34. for(i=0;i<101;i++){
  35. add=num1[i]+num2[i]+c;
  36. c=add/20;
  37. num3[j]=add%20;
  38. j--;
  39. }
  40. if(c==1)
  41. num3[j]=1;
  42. }
  43. void print(int* num){
  44. int i,j=0;
  45. while(num[j]==0)j++;
  46. if(j>101){
  47. printf("0\n");
  48. }
  49. else{
  50. for(;j<102;j++){
  51. printf("%c",Digit[num[j]]);
  52. }
  53. printf("\n");
  54. }
  55. }

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. POJ 2253 Frogger 最短路 难度:0

    http://poj.org/problem?id=2253 #include <iostream> #include <queue> #include <cmath&g ...

  2. js字符转换成整型 parseInt()函数规程Number()函数

    今天在做一个js加法的时候,忘记将字符转换成整型,导致将加号认为是连接符,  在运算前要先对字符井行类型转换,使用parseInt()函数   使用Number()将字符转换成int型效果更好

  3. 线程系列4---sleep()和wait()方法区别

    2013-12-25 14:49:00 1. sleep()方法是Thread类的一个静态方法,可以在任意地方被调用,而wait()方法是object类的一个方法,只能在同步代码块或者同步方法里面,通 ...

  4. 2、IValueConverter应用

    1.C#代码如下: public class logotoimgConverter:IValueConverter { //将logo转换为URI public object Convert(obje ...

  5. 一台服务器搭载两个tomcat项目

    之前下载的mysql  在官网是有 历史库的 如果现在一台机器上已经部署了一个tomcat服务,无论这个tomcat是否已经注册为服务了,或者没有注册windows服务,或者注册了,都没关系.都可以采 ...

  6. Xutils的使用 转载 带自己细细研究

    单例模式static DbUtils db = null; public static DbUtils getDb(Context context) { if (context == null) { ...

  7. flash 和 第三方程序交互

    一.flash 端 修改 1.flash cs6  修改脚本 为as3 2.修改 按钮 实例 名 (不是sprite列表中的名字  实例名称 和这个名字 是2个) 3.时间轴上 添加代码 当前选择 A ...

  8. java基础-004

    ---恢复内容开始--- 14.Java集合类框架的基本接口 集合类接口指定了一组叫做元素的对象.集合类接口的每一种具体的实现类都可以选择以它自己的方式对元素进行保存和排序.有的集合类允许重复的键,有 ...

  9. 在iis6.0公布asp.net mvc3网站

    在iis6.0发布asp.net mvc3网站 这个问题一直困扰了我很长一段时间,终于在今天综合网上查的资料把它解决了. 在iis6.0发布asp.net mvc3网站 1   需要在服务器下安装.n ...

  10. 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 ...