最近突然想往算法方向走走,做了做航电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. 链表反转leetcode206

    最近准备结束自己的科研生涯,准备要开始找工作了,准备在LEETCODE刷刷题...刷的前40题全部用python刷的,各种调包速度奇快,后被师哥告知这样没意义,于是准备开始回归C++,Python用的 ...

  2. 练习JavaScript实现过滤特殊字符

    for循环遍历特殊字符和用户输入字符,然后做比较,返回结果. <script type="text/javascript"> var name = prompt(&qu ...

  3. OS命令注入中的空格

    1.bash 空格可以替换为%20.%09(tab).%2b(+) in url.{IFS} 2.Win shell 空格可以替换为%20.%09(tab).%0b.%0c.%2b(+) in url

  4. BZOJ3670 [Noi2014]动物园

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...

  5. Smallest Common Multiple

    FCC题目:找出能被两个给定参数和它们之间的连续数字整除的最小公倍数. 范围是两个数字构成的数组,两个数字不一定按数字顺序排序. 例如对 1 和 3 -- 找出能被 1 和 3 和它们之间所有数字整除 ...

  6. python爬乌云dorps文章

    有时候翻看drops 无赖drops没有一个全部文章列表,所以就有了这个想法把所有文件标题链接都爬出来这样又直观又好找感兴趣的文章 #coding=utf-8 import re import url ...

  7. 推荐一款Mac上好用的Markdown编辑器

    [TOC] 推荐一款Mac上好用的Markdown编辑器 正文 我算是一位Evernote的重度用户吧.之前也尝试过为知笔记,有道云笔记,微软的onenote,最后还是觉的Evernote.因为我喜欢 ...

  8. Express4+Mongodb超简单入门实例

    开始前,请确保mongodb已经能正常工作,安装教程:windows下MongoDB的安装及配置 , 请自行安装配置.下面进入正文: 第一步:命令行创建数据库.表,并插入一条数据 命令如下: //创建 ...

  9. 微软unity 注入mvc

    首先获取开源unity ,引用, 新建UnityDependencyResolver 继承IDependencyResolver,代码如下: public class UnityDependencyR ...

  10. selenium 页面截图并保存

    import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; import org. ...