hdu1002
2016-01-24 23:19
441 查看
hdu1002 高精度加法水题一道
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <map> #include <algorithm> #include <cmath> #include <iomanip> #include <vector> #include <stack> #include <cstdlib> #include <queue> #include <set> #include <cctype> using namespace std; #define loop(i,u,v) for(int i = u;i <= v;i++) #define rloop(i,u,v) for(int i = u;i >= v;i--) #define eps 0.00000001 void reverse(char *a) { char *first = &a[0]; char *last = &a[strlen(a)-1]; for(;first < last ; first++,last--) { char x = *first; *first = *last; *last = x; } } int main() { string a,b,c,d; int num[1100]; int n; cin >> n; loop(i,1,n) { memset(num,0,sizeof(num)); cin >> a >> b; c = a; d = b; reverse(&a[0]); reverse(&b[0]); int la = a.size(); int lb = b.size(); int lmin = min(la,lb); int lmax = max(la,lb); int x = 0; int last = lmin - 1; if(lb > la) swap(a,b); loop(j,0,last) { num[j] += (int)a[j] + (int)b[j] - '0' - '0'; if(num[j] >= 10) { num[j+1] = 1; num[j] -= 10; } } loop(j,lmin,lmax-1) num[j] += (int)a[j] - '0'; if(num[lmax] > 9) { num[lmax+1] = 1; num[lmax] -= 10; lmax++; } else if(num[lmax]) lmax++; printf("Case %d:\n",i ); printf("%s + %s = ",&c[0],&d[0] ); rloop(j,lmax-1,0) cout << num[j]; cout << endl; if(i < n) cout << endl; } return 0; }
相关文章推荐
- android mvp快速开发框架介绍(继续dileber)
- Entity Framework 6 Recipes 2nd Edition(11-4)译 -> 在”模型定义”函数里调用另一个”模型定义”函数
- 网站系统技术
- car认证中心配置
- 网上图书商城项目学习笔记-002登录页面的静态设计
- IOS中获取各种文件的目录路径的方法()
- ubuntu 64位下轻松安装mongodb
- car认证中心配置
- 老僧长谈设计模式-5-装饰者模式
- RecyclerView 和 DataBinding
- Codeforces Round #340 (Div. 2) B. Chocolate 水题
- Efficient Graph-Based Image Segmentation解读
- 打印super_block结构中的一些域的值
- Codeforces Round #329 (Div. 2) D. Happy Tree Party(树链剖分)
- 自定义Directive使用ngModel
- 面向对象程序设计 ——第一次作业
- kuangbin_SegTree A (HDU 1166)
- BigDecimal用法详解
- 2015年大二上-数据结构-图-1-(4)-利用遍历思想求解图问题(2)
- printf的输出相关