最近突然想往算法方向走走,做了做航电acm的几道题

二话不说,开始

航电acm 1002 题主要是处理长数据的问题,算法原理比较简单,就是用字符数组代替int,因为int太短需要处理的数据较长

下面是问题描述:

Problem Description
I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
 

 

Input
The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line consists of two positive integers, A and B. Notice that the integers are very large, that means you should not process them by using 32-bit integer. You may assume the length of each integer will not exceed 1000.
 
Output
For each test case, you should output two lines. The first line is "Case #:", # means the number of the test case. The second line is the an equation "A + B = Sum", Sum means the result of A + B. Note there are some spaces int the equation. Output a blank line between two test cases.
 
Sample Input
2 1 2 112233445566778899 998877665544332211
 
Sample Output
Case 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110
 
Author
Ignatius.L

下面列出我的代码 参考http://blog.csdn.net/odaynot/article/details/8049632

#include<stdio.h>
#include<string.h>
int toInt(char c){
return c-'';
}
int main(){
int i, n,j=,al,bl,ml,t;
char a[], b[];//存储输入的两个数
int count[];
scanf("%d",&n);
while(n--){
if(j!=)printf("\n");
scanf("%s",a);
al=strlen(a);//返回字符串结束符之前的字符个数
scanf("%s",b);
bl=strlen(b);
ml=(al>bl)?al:bl;//获取较长的字符长度
t=ml;
for(i=;i<=ml;i++)count[i]=;//初始化数组
for(ml;al>&&bl>;ml--){
count[ml]+=toInt(a[--al])+toInt(b[--bl]);
if(count[ml]/){
//处理进位问题
count[ml-]++;
count[ml]=count[ml]%;
}
}
while(al>){
count[ml--]+=toInt(a[--al]);
if(count[ml+]/){
count[ml]++;
count[ml+]%=;
}
}
while(bl>){
count[ml--]+=toInt(b[--bl]);
if(count[ml+]/){
count[ml]++;
count[ml+]%=;
}
} printf("Case %d:\n%s + %s =",j++,a,b);
for(i=;i<=t;i++){
if(i==&&count[i]==){
i++;
}
printf("%d",count[i]);
}
printf("\n");
}
return ;
}

欢迎批评,疑问请留言

acm 1002 算法设计的更多相关文章

  1. acm常见算法及例题

    转自:http://blog.csdn.net/hengjie2009/article/details/7540135 acm常见算法及例题  初期:一.基本算法:     (1)枚举. (poj17 ...

  2. ACM常用算法及练习(1)

    ACM常用算法及练习 第一阶段:练经典常用算法,下面的每个算法给我打上十到二十遍,同时自己精简代码,因为太常用,所以要练到写时不用想,10-15分钟内打完,甚至关掉显示器都可以把程序打出来. 1.最短 ...

  3. 『嗨威说』算法设计与分析 - 贪心算法思想小结(HDU 2088 Box of Bricks)

    本文索引目录: 一.贪心算法的基本思想以及个人理解 二.汽车加油问题的贪心选择性质 三.一道贪心算法题点拨升华贪心思想 四.结对编程情况 一.贪心算法的基本思想以及个人理解: 1.1 基本概念: 首先 ...

  4. 算法设计与分析 - AC 题目 - 第 5 弹(重复第 2 弹)

    PTA-算法设计与分析-AC原题 - 最大子列和问题 (20分) 给定K个整数组成的序列{ N1, N2, ..., NK },“连续子列”被定义为{ Ni, Ni+, ..., Nj },其中 ≤i ...

  5. 算法设计与分析 - AC 题目 - 第 2 弹

    PTA-算法设计与分析-AC原题7-1 最大子列和问题 (20分)给定K个整数组成的序列{ N1, N2, ..., NK },“连续子列”被定义为{ Ni, Ni+1, ..., Nj },其中 1 ...

  6. OOP: One pont of view of OOP与基于算法设计的区别

    ..摘自<C++网络编程 卷1:运用ACE和模式消除复杂性> <C++ Network Programming Volume 1 Mastering Complexity with ...

  7. Python数据结构与算法设计总结篇

    1.Python数据结构篇 数据结构篇主要是阅读[Problem Solving with Python]( http://interactivepython.org/courselib/static ...

  8. 算法设计和数据结构学习_5(BST&AVL&红黑树简单介绍)

    前言: 节主要是给出BST,AVL和红黑树的C++代码,方便自己以后的查阅,其代码依旧是data structures and algorithm analysis in c++ (second ed ...

  9. ACM常用算法及练习(2)

    ACM常用算法及练习 知识类型 重要度 容易度 应掌握度 典型题 其他           数据结构(5) 链表 ★★☆ ★★★ ★★☆     栈 stack ★★★ ★★★ ★★★ HLoj120 ...

随机推荐

  1. Junit的使用

    Junit是用于编写单元测试的框架.对于已经写好的函数,可以使用Junit生成单元测试代码. 自己的环境是:Linux Java环境是:JDK1.7 IDE:Eclipse Java EE IDE f ...

  2. JS this指向

    正常模式 在正常模式下独立函数的的 this 指向 undefined 或 window. <script type="text/javascript"> functi ...

  3. video.js-H5视频播放库

    video.js是一款很流行的html5视频播放插件.很适合在移动端播放视频(比如微信网页),功能强大,且支持降级到flash,兼容ie8.官网:http://videojs.com/    git& ...

  4. php ob_flush 和flush

    “ob_flush()和flush()的区别.前者是把数据从PHP的缓冲中释放出来,后者是把不在缓冲中的或者说是被释放出来的数据发送到浏览器.所以当缓冲存在的时候,我们必须ob_flush()和flu ...

  5. Centos6.5下docker 环境搭建

    一.运行docker Linux内核版本需要在3.8以上,针对centos6.5 内核为2.6的系统需要先升级内核.不然会特别卡,退出容器. 在yum的ELRepo源中,有mainline(3.13. ...

  6. G:首页调用“图片视频”的分类和文章(难点)

      1:后台获取:自定义分类的ID (默认分类也可获取)  2:动态获取"自定义分类的ID($cat)"  $cat_title = single_cat_title(' ', f ...

  7. 决策树及R语言实现

    决策树是什么 决策树是基于树结构来进行决策,这恰是人类在面临决策问题时一种很自然的处理机制.例如,我们要对"这是好瓜吗?"这样的问题进行决策时,通常会进行一系列的判断或" ...

  8. GET和POST有什么区别?及为什么网上的多数答案都是错的

    如果有人问你,GET和POST,有什么区别?你会如何回答? 最普遍的答案 回来之后寻思了很久,他到底是想问我什么?我一直就觉得GET和POST没有什么除了语义之外的区别,自打我开始学习Web编程开始就 ...

  9. C程序汇编运行模式简析

    SJTUBEAR 原创作品转载请注明出处 /<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 1. 汇编 ...

  10. 释放修改OS X 10.11系统文件权限【转】

    序言:有时要替换相关的(系统目录下的)文件以完成软件的破解,但在 OS X 10.11 系统图形界面下,Root(系统超级用户)已‘转变’为 Administrator(管理员用户),选择系统文件夹( ...