高精度------C++
高精度运算------C++
(加减乘除)









例:ZOJ2001 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1001
The Antique Comedians of Malidinesia prefer comedies to tragedies. Unfortunately, most of the ancient plays are tragedies. Therefore the dramatic advisor of ACM has decided to transfigure some tragedies into comedies. Obviously, this work is very hard because the basic sense of the play must be kept intact, although all the things change to their opposites. For example the numbers: if any number appears in the tragedy, it must be converted to its reversed form before being accepted into the comedy play.
Reversed number is a number written in arabic numerals but the order of digits is reversed. The first digit becomes last and vice versa. For example, if the main hero had 1245 strawberries in the tragedy, he has 5421 of them now. Note that all the leading zeros are omitted. That means if the number ends with a zero, the zero is lost by reversing (e.g. 1200 gives 21). Also note that the reversed number never has any trailing zeros.
ACM needs to calculate with reversed numbers. Your task is to add two reversed numbers and output their reversed sum. Of course, the result is not unique because any particular number is a reversed form of several numbers (e.g. 21 could be 12, 120 or 1200 before reversing). Thus we must assume that no zeros were lost by reversing (e.g. assume that the original number was 12).
Input
The input consists of N cases. The first line of the input contains only positive integer N. Then follow the cases. Each case consists of exactly one line with two positive integers separated by space. These are the reversed numbers you are to add.
Output
For each case, print exactly one line containing only one integer - the reversed sum of two reversed numbers. Omit any leading zeros in the output.
Sample Input
3
24 1
4358 754
305 794
Sample Output
34
1998
1
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
const int maxn=1005;
using namespace std; int main()
{
int n;
//freopen("Atext.in","r",stdin);
cin >> n;
while(n--){
string a,b;
int flag=0,n,m,len,i;
int num1[maxn]={0},num2[maxn]={0},ans[maxn]={0};
cin >> a >> b;
n=a.size();
for(int i=0;i<n;i++){
num1[i]=a[i]-'0';
}
m=b.size();
for(int i=0;i<m;i++){
num2[i]=b[i]-'0';
}
len=n>m? n:m;
for(i=0;i<len;i++){
ans[i]+=num1[i]+num2[i]; //反向数之和
if(ans[i]>9){
ans[i]-=10;
ans[i+1]++;
}
}
/*for(int i=0;i<len/2;i++){
swap(ans[i],ans[len-i-1]); //将和逆序
}*/
if(ans[len]!=0)len++;
for(i=0;i<len;i++){
if(ans[i]!=0||flag==1){
cout << ans[i];
flag=1;
}
}
cout << endl;
}
return 0;
}
高精度------C++的更多相关文章
- CSharpGL(28)得到高精度可定制字形贴图的极简方法
CSharpGL(28)得到高精度可定制字形贴图的极简方法 回顾 以前我用SharpFont实现了解析TTF文件从而获取字形贴图的功能,并最终实现了用OpenGL渲染文字. 使用SharpFont,美 ...
- 递推+高精度 UVA 10497 Sweet Child Makes Trouble(可爱的孩子惹麻烦)
题目链接 题意: n个物品全部乱序排列(都不在原来的位置)的方案数. 思路: dp[i]表示i个物品都乱序排序的方案数,所以状态转移方程.考虑i-1个物品乱序,放入第i个物品一定要和i-1个的其中一个 ...
- [Template]高精度模板
重新写一下高精度模板(不要问我为什么) 自认为代码风格比较漂亮(雾 如果有更好的写法欢迎赐教 封装结构体big B是压位用的进制,W是每位长度 size表示长度,d[]就是保存的数字,倒着保存,从1开 ...
- Code[VS] 3123 高精度练习之超大整数乘法
FFT 做 高精度乘法 #include <bits/stdc++.h> ); struct complex { double a, b; inline complex( , ) { a ...
- Java 高精度数字
BigInteger // 高精度整数 BigDecimal //高精度小数 小数位数不受限制
- c++减法高精度算法
c++高精度算法,对于新手来说还是一大挑战,只要克服它,你就开启了编程的新篇章,算法. 我发的这个代码并不是很好,占用内存很多而且运行时间很长(不超过0.02秒),但是很好理解,很适合新手 高精算法的 ...
- c++加法高精度算法
c++高精度算法,对于新手来说还是一大挑战,只要克服它,你就开启了编程的新篇章,算法. 我发的这个代码并不是很好,占用内存很多而且运行时间很长(不超过1秒),但是很好理解,很适合新手 高精算法的本质就 ...
- [转]使用Stopwatch类实现高精度计时
对一段代码计时同查通常有三种方法.最简单就是用DateTime.Now来进行比较了,不过其精度只有3.3毫秒,可以通过DllImport导入QueryPerformanceFrequency和Quer ...
- .net平台下获取高精度时间类
原文:http://www.it118.org/specials/321869dd-98cb-431b-b6d2-82d973cd739d/d940a15c-0d36-4369-8de0-b07cf3 ...
- [vijos P1040] 高精度乘法
如果这次noip没考好,完全是因为从7月29日之后就没有再写过程序了.说起来,真是一个泪流满面的事实… 那这样一个弱智题练手恢复代码能力,竟然还花了我两个晚上(当然不是两整个晚上…) 第一天TLE了, ...
随机推荐
- 2021.06.18 思科anyconnect安全移动客户端通知
mac系统更新后,开关机后都会弹出思科anyconnect安全移动客户端通知的弹框,很烦,所以要干掉它! 打开终端,执行以下两行命令即可: cd /Library/LaunchAgents/ mv / ...
- .DS_Store泄露利用过程
.DS_Store文件泄漏利用工具: ds_store_exp.DS_Store是Mac下Finder用来保存如何展示 文件/文件夹 的数据文件,每个文件夹下对应一个. 如果开发/设计人员将.DS_S ...
- fatal: unable to access 'https://github.com/github-eliviate/papers.git/': Failed to connect to github.com port 443 after 21107 ms: Timed out
fatal: unable to access 'https://github.com/github-eliviate/papers.git/': Failed to connect to githu ...
- ElasticSearch 实现分词全文检索 - term、terms查询
数据准备 ElasticSearch 实现分词全文检索 - 测试数据准备 ElasticSearch的各种查询 不会对查询关键字进行分词 term 查询 term的查询是代表完全匹配,搜索之前不会对你 ...
- 对于实现上一篇遇到的问题——MyBatis+增删改查(已解决)
问题一:该Http不支持Get/Post方法 我根据网上的解决方法将Get和Post的位置来回换,还是不停报错: 后来偶然间看到一个博主发的"你的代码写在Get或者Post里面,就将没写代码 ...
- 声网Agora发布教育信息化解决方案 助力教育公平提效
4月23日-25日,由中国教育装备行业协会主办的第79届教育装备展在厦门国际会展中心举办.作为赋能教育信息化的实时互动PaaS服务商,声网Agora应邀参会.展会现场,声网展示了基于实时音视频互动能力 ...
- AES算法流程
明文分组长度: \(128bit\) 密钥长度: \(128bit\) 迭代轮数: \(10轮\) 加密和解密均在\(4*4\)的矩阵上进行,每个格子\(1\)个字节,共\(16\)个字节\(128b ...
- axios和后端交互时,参数需要写在body和query中同时写
axios.post('/api/xxx',{ // post body },{ params: { // query } }) demo: let params = { _id:this.alarm ...
- kubernetes(k8s)中部署dashboard可视化面板
Web 界面 (Dashboard) Dashboard 是基于网页的 Kubernetes 用户界面.你可以使用 Dashboard 将容器应用部署到 Kubernetes 集群中,也可以对容器应用 ...
- 搭建Hadoop2.7.2和Hive2.3.3以及Spark3.1.2
Hadoop 简介 Hadoop是一个用Java编写的Apache开源框架,允许使用简单的编程模型跨计算机集群分布式处理大型数据集.Hadoop框架工作的应用程序在跨计算机集群提供分布式存储和计算的环 ...