PAT (Advanced Level) 1023. Have Fun with Numbers (20)
手动模拟一下高精度加法。
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<map>
#include<queue>
#include<vector>
using namespace std; char s[],t[],c[];
int lens,lenc; void f(char *x)
{
int len=strlen(x);
for(int i=;i<len/;i++) swap(x[i],x[len-i-]);
} void add()
{
int k=;
int len=strlen(s);
int num1,num2; for(int i=;i<=len;i++)
{
if(s[i]==) num1=num2=;
else num1=num2=s[i]-'';
c[i]=(num1+num2+k)%+'';
k=(num1+num2+k)/;
}
if(c[len]=='') c[len]=;
f(c);
// printf("%s\n",c);
} bool check()
{
char tmps[],tmpc[];
if(lens!=lenc) return ;
strcpy(tmps,s); strcpy(tmpc,c);
sort(tmps,tmps+lens); sort(tmpc,tmpc+lenc);
for(int i=;s[i];i++) if(tmps[i]!=tmpc[i]) return ;
return ;
} int main()
{
memset(s,,sizeof s);memset(t,,sizeof t);memset(c,,sizeof c);
scanf("%s",s); strcpy(t,s);
f(s); f(t); add(); f(s);
lens=strlen(s);lenc=strlen(c);
if(check()) printf("Yes\n");
else printf("No\n");
printf("%s\n",c);
return ;
}
PAT (Advanced Level) 1023. Have Fun with Numbers (20)的更多相关文章
- PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642
PAT (Advanced Level) Practice 1027 Colors in Mars (20 分) 凌宸1642 题目描述: People in Mars represent the c ...
- PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642
PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...
- PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642
PAT (Advanced Level) Practice 1005 Spell It Right (20 分) 凌宸1642 题目描述: Given a non-negative integer N ...
- PAT (Advanced Level) Practice 1001 A+B Format (20 分) 凌宸1642
PAT (Advanced Level) Practice 1001 A+B Format (20 分) 凌宸1642 题目描述: Calculate a+b and output the sum i ...
- PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642
PAT (Advanced Level) Practice 1011 World Cup Betting (20 分) 凌宸1642 题目描述: With the 2010 FIFA World Cu ...
- PTA (Advanced Level) 1023 Have Fun with Numbers
Have Fun with Numbers Notice that the number 123456789 is a 9-digit number consisting exactly the nu ...
- PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) (进制转换,回文数)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Nu ...
- PAT (Advanced Level) Practice 1027 Colors in Mars (20 分)
People in Mars represent the colors in their computers in a similar way as the Earth people. That is ...
- PAT (Advanced Level) Practice 1054 The Dominant Color (20 分)
Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of i ...
随机推荐
- shell编程之服务脚本编写,文件锁以及信号捕获
shell脚本编程是linux运维工程师必备的技能,也是非常重要的一个技能,所以把shell编程学好,只有好处.基础语法我也就不讲了,学过C语言这些语言的,稍微看一下就能明白shell编程的基础,所以 ...
- MySQL源码安装(centos)
1.去MySQL官网下载源码包 地址:http://dev.mysql.com/downloads/mysql/ 下载完后需要检查文件的MD5,以确认是否从官网下载的原版本(以防被人篡改过该软件) 使 ...
- rownum使用方法
rownum使用方法: .使用rownum子查询: rownum是一个总是从1开始的伪列,当查询条件rownum)时,不能从数据库查到记录,因此要 通过子查询解决:; 结果: SQL; R ID US ...
- asp:cookies的属性
Expires – 过期时间.指定cookie的生命期.具体是值是过期日期.如果想让cookie的存在期限超过当前浏览器会话时间,就必须使用这个属性.当过了到期日期时,浏览器就可以删除cookie文件 ...
- 报错 BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext 的解决方法
这个普遍是因为tomcat 的 jar包问题,重新导入一下tomcat的jar包就OK了.
- Android OpenGL ES(十四)gl10方法解析
Android 支持 OpenGL 列表 1.GL 2.GL 10 3.GL 10 EXT 4.GL 11 5.GL 11 EXT 6.GL 11 ExtensionPack 我们将使用 GL10 这 ...
- POJ 2975 Nim 尼姆博弈
题目大意:尼姆博弈,求先手必胜的情况数 题目思路:判断 ans=(a[1]^a[2]--^a[n]),求ans^a[i] < a[i]的个数. #include<iostream> ...
- LightOJ 1058 平行四边形的判断定理
题目大意:给你n个点,求这n个点最多能组成多少个平行四边形. 题目思路:这道题卡时间,而且卡内存.你要尽可能的想办法优化. 平行四边形的判定定理: 两组对边分别平行的四边形是平行四边形(定义判定法): ...
- UVALive 2678 大于s的最短子序列和
input n s 10<=n<=100000,s<1e9 a1 a2 ... an ai<=10000 output 大于s的最短子序列和的长度,没有输出0 #includ ...
- 实验用rootkit
进程对比实验用得到rootkit: 1.FU rootkit 简单的来说,FU是一个隐藏进程的工具.,FU_Rootkit是开源的,用C语言编写.FU_Rootkit主程序包括2个部分:Fu.exe和 ...