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 ...
随机推荐
- svn rollback: 恢复到上一版本
18:48:32svn的文件版本是168,我想用167的版本覆盖掉168的版本如何搞? 18:52:47先把本地的那个文件用rm命令删掉,然后,使用svn up -r 167 文件路径,UP下来的文件 ...
- Oracle用户密码过期和用户被锁解决方法【转】
[原因/触发因素] 确定是由于Oracle11g中默认在default概要文件中设置了“PASSWORD_LIFE_TIME=180天”所导致. [影响和风险] 影响 密码过期后,业务进程连接数据库异 ...
- 让您的Xcode键字如飞
手指在键盘上飞速跳跃,终端上的代码也随着飞舞,是的这确实很酷.优秀的程序员总是这么一群人,他们不拘于现状,不固步自封,他们喜欢新奇的事,他们把自己发挥到极致. 指法攻略 放下您钟爱的鼠标吧,在前行之中 ...
- curl 测试web站点的响应时间
curl -s -w "\n"::%{time_namelookup}::%{time_connect}::%{time_starttransfer}::%{time_total} ...
- UIActivityIndicatorView的详细使用(加载菊花)
UIActivityIndicatorView实例提供轻型视图,这些视图显示一个标准的旋转进度轮.当使用这些视图时,最重要的一个关键词是小.20×20像素是大多数指示器样式获得最清楚显示效果的大小.只 ...
- Category / Extention / 属性 / 成员变量 /
转载自:http://blog.csdn.net/itianyi/article/details/8618128 在ios第一版中,我们为输出口同时声明了属性和底层实例变量,那时,属性是oc语言的一个 ...
- angular初始用——简易购物车
<html> <head> <meta charset="utf-8"> <script src="js/angular.js& ...
- 关于c中的inline
在c中,为了解决一些频繁调用的小函数大量消耗栈空间或是叫栈内存的问题,特别的引入了inline修饰符,表示为内联函数.栈空间就是指放置程式的局部数据也就是函数内数据的内存空间,在系统下,栈空间是有限的 ...
- JQuery选择所有标题的元素
$(":header") 参考:http://www.w3school.com.cn/jquery/selector_header.asp
- Ubuntu 12.04和Windows 7双系统安装图解
http://wenku.baidu.com/link?url=PZlnNOhY0SjHDW-teFFnCMzPYJVjx7vj6yWY-o5HHFLuFqhLI4uFcQVu_y0_6i7vpSnz ...