HDOJ1002
#include <iostream>
#include<stdio.h>
using namespace std;
int main()
{
int T, count_T;
char a[1001], b[1001], ans[1002];
cin >> T;
for(count_T=1; count_T <= T; count_T++) {
cin >> a >> b;
int la=strlen(a)-1, lb=strlen(b)-1, sign=0, i;
for(i=0;la>=0 && lb>=0; la--,lb--,i++) {
sign += a[la] + b[lb] - '0' - '0';
ans[i] = sign % 10;
sign /= 10;
}
for(; la>=0; la--, i++) {
sign += a[la] - '0';
ans[i] = sign % 10;
sign /= 10;
}
for(; lb>=0; lb--, i++) {
sign += b[lb] - '0';
ans[i] = sign % 10;
sign /= 10;
}
if(sign) {
ans[i] = sign;
i++;
}
if(count_T!=1)
printf("\n") ;
printf("Case %d:\n",count_T) ;
printf("%s + %s = ",a,b);
// 正向输入反向输出!!!不必考虑怎么在头位置加进位的问题。
for(i--; i>=0; i--) {
cout << (char)(ans[i] + '0');
}
cout << endl ;
}
return(0);
}
快疯了
#include <stdio.h>
#include<string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int j,count;
char a[1001], b[1001], ans[1002];
scanf("%d", &count);
while(j++<count)
{
scanf("%s%s",a, b);
if(j== 1)
printf("Case %d:\n", j);
else
printf("\nCase %d:\n", j);
int la=strlen(a)-1,lb=strlen(b)-1,sign=0,i;
for(i=0;la>=0 && lb>=0; la--,lb--,i++) {
sign += a[la] + b[lb] - '0' - '0';
ans[i] = sign % 10;
sign /= 10;
}
for(; la>=0; la--, i++) {
sign += a[la] - '0';
ans[i] = sign % 10;
sign /= 10;
}
for(; lb>=0; lb--, i++) {
sign += b[lb] - '0';
ans[i] = sign % 10;
sign /= 10;
}
if(sign) {
ans[i] = sign;
i++;
}
// 正向输入反向输出!!!不必考虑怎么在头位置加进位的问题。
printf("%s + %s = ", a, b);
for(i--; i>=0; i--) {
printf("%d", ans[i]);
}
}
return 0;
}
HDOJ1002的更多相关文章
- HDOJ-1002
用java写大数,感觉就是BUG import java.math.*; import java.io.*; import java.util.*; public class Main{ public ...
- HDOJ1002题A + B Problem II,2个大数相加
Problem Description I have a very simple problem for you. Given two integers A and B, your job is to ...
- HDOJ-1002 A + B Problem II (非负大整数相加)
http://acm.hdu.edu.cn/showproblem.php?pid=1002 输入的数都是正整数,比较好处理,注意进位. //非负大整数加法 # include <stdio.h ...
- 140730暑期培训.txt
1.大数加减法 思路分析: 1.将数据当做字符串输入(gets(s)) 2.将字符型转换为整型,逆着存 char? int i=0,j ...
- ACM中使用 JAVA v2. 1
ACM中使用JAVA v2.1 严明超 (Blog:mingchaoyan.blogbus.com Email:mingchaoyan@gmail.com) 0.前 言 文前声明:本文只谈java用于 ...
随机推荐
- WordPress的编译器功能扩展
//php代码如下://向文章编辑器的Visual区添加自定义按钮,js文件存放在wp-content/plugins/文件夹下 add_action('admin_head', 'my_custom ...
- Ubuntu Software Center has closed unexpectly解决方案
打开软件中心Ubuntu Software Center的时候 出现crash report :The application Ubuntu Software Center has closed un ...
- WPF之DataAnnotations 注解说明
参考:https://www.cnblogs.com/yaosuc/p/4527886.html 1.基础验证: using System.ComponentModel.DataAnnotations ...
- 牛腩新闻发布系统(一):SQLHelper重构(一)
导读:在机房重构的时候,就用到了SQLHelper,但那时候即使把代码反复看了很多遍,也看了注释,还和同学交流,也依然是半懂不懂.现在,我再次用到了SQLhelper这个东西,就来说说SQLHelpe ...
- shell的if-else的基本用法
if 语句通过关系运算符判断表达式的真假来决定执行哪个分支.Shell 有三种 if ... else 语句: if ... fi 语句: if ... else ... fi 语句: if ... ...
- vue 组件高级用法实例详解
一.递归组件 组件在它的模板内可以递归地调用自己, 只要给组件设置name 的选项就可以了. 示例如下: <div id="app19"> <my-compone ...
- [TJOI2009]开关 (线段树)
题目描述 现有N(2 ≤ N ≤ 100000)盏灯排成一排,从左到右依次编号为:1,2,......,N.然后依次执行M(1 ≤ M ≤ 100000)项操作,操作分为两种:第一种操作指定一个区间[ ...
- 查看Linux每个进程的流量和带宽
原文:https://blog.csdn.net/monkeynote/article/details/45867803 作为一个系统管理员,有时候需要搞清楚一台机器上的哪个进程占用了较高的网络带宽. ...
- springboot收集
Spring Boot实战:拦截器与过滤器 参考:https://blog.csdn.net/m0_37106742/article/details/64438892 https://www.ibm. ...
- ScrollPic.js——图片左右滚动插件
自己在做项目的时候刚好遇到了图片做左右滚动的项目,发现ScrollPic.js这个插件还是很好用的,一般的浏览器都支持,也可以做成bootstrap样式: 首先需要下载ScrollPic.js这个插件 ...