和1024一样都是大数据的题,因为位数最多要20位,long long最多19位
给一个num,求sum=num+num
问sum包含的数字,是否是num的一个排列,即数字都一样,只是顺序不同罢了。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <string>
using namespace std;
const int maxn=; struct Bign{
int len,num[maxn]; // 这里num[0]是最低位,num[len-1]是最高位
Bign(){
memset(num,,sizeof(num));
len=;
}
Bign(int val){
*this=val;
}
Bign(const char*val){
*this=val;
}
//以int型赋值
Bign operator=(int val){
char s[maxn];
sprintf(s,"%d",val);
*this=s; //字符串赋值
return *this;
}
//以字符串赋值
Bign operator=(const char*val){
len=strlen(val);
for(int i=;i<len;i++){
num[i]=val[len--i]-'';
}
return *this;
}
//去掉前导0
void clean(){
while(len>&&!num[len-]){
len--;
}
}
//转化为字符串
string tostr(){
string res="";
clean();
for(int i=;i<len;i++){
res=(char)(num[i]+'')+res;
}
if(res=="")
return "";
return res;
}
//重载+
Bign operator+(const Bign& b)const{
Bign c;
c.len=;
for(int i=,g=;g||i<max(len,b.len);i++){
int x=g;
if(i<len)
x+=num[i];
if(i<b.len)
x+=b.num[i];
c.num[c.len++]=x%;
g=x/;
}
return c;
}
//取翻转后的数
Bign toReverse(){
clean();
Bign c;
c.len=len;
for(int i=;i<len;i++){
c.num[i]=num[len--i];
}
return c;
} };
int main()
{
char str[];
scanf("%s",str);
Bign num=str;
Bign sum=num+num;
int vis1[],vis2[];
memset(vis1,,sizeof(vis1));
memset(vis2,,sizeof(vis2));
for(int i=;i<num.len;i++){
vis1[num.num[i]]=;
}
for(int i=;i<sum.len;i++){
vis2[sum.num[i]]=;
}
bool flag=true;
for(int i=;i<;i++){
if(vis1[i]!=vis2[i]){
flag=false;
}
}
if(flag){
printf("Yes\n");
}
else{
printf("No\n");
}
string s=sum.tostr();
cout<<s<<endl;
return ;
}

PAT甲题题解-1023. Have Fun with Numbers (20)-大数加法的更多相关文章

  1. PAT甲题题解-1058. A+B in Hogwarts (20)-大水题

    无语,这种水题还出,浪费时间,但又不得不A... #include <iostream> #include <cstdio> #include <algorithm> ...

  2. PAT甲题题解-1031. Hello World for U (20)-字符串处理,水

    #include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...

  3. PAT甲题题解-1104. Sum of Number Segments (20)-(水题)

    #include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...

  4. PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642 题目描述: Notice that the number ...

  5. PAT甲题题解-1068. Find More Coins (30)-dp,01背包

    一开始没多想,虽然注意到数据N<=10^4的范围,想PAT的应该不会超时吧,就理所当然地用dfs做了,结果最后一组真的超时了.剪枝啥的还是过不了,就意识到肯定不是用dfs做了.直到看到别人说用0 ...

  6. PAT甲题题解-1008. Elevator (20)-大么个大水题,这也太小瞧我们做题者的智商了

    如题... #include <iostream> #include <cstdio> #include <algorithm> #include <cstr ...

  7. PAT甲题题解-1010. Radix (25)-二分搜索

    题意:给出n1和n2,以及其中一个数的进制,问另一个数是多少进制的情况下,才会是两个数相等.不存在的话,则输出Impossible 这题思路很简单,但是要考虑的比较多,在简单题里面算是比较好的. 有两 ...

  8. PAT甲题题解-1011. World Cup Betting (20)-误导人的水题。。。

    题目不严谨啊啊啊啊式子算出来结果是37.975样例输出的是37.98我以为是四舍五入的啊啊啊,所以最后输出的是sum+0.005结果告诉我全部错误啊结果直接保留两位小数就可以了啊啊啊啊 水题也不要这么 ...

  9. PAT甲题题解-1012. The Best Rank (25)-排序水题

    排序,水题因为最后如果一个学生最好的排名有一样的,输出的课程有个优先级A>C>M>E那么按这个优先级顺序进行排序每次排序前先求当前课程的排名然后再与目前最好的排名比较.更新 至于查询 ...

随机推荐

  1. 在Linux服务器上运行Jupyter notebook server教程

    在Linux服务器上运行Jupyter notebook server教程 很多deep learning教程都推荐在jupyter notebook运行python代码,方便及时交互.但只在本地运行 ...

  2. 详解动态规划(Dynamic Programming)& 背包问题

    详解动态规划(Dynamic Programming)& 背包问题 引入 有序号为1~n这n项工作,每项工作在Si时间开始,在Ti时间结束.对于每项工作都可以选择参加与否.如果选择了参与,那么 ...

  3. win10下nvidia控制面板看不到

    64位win10,nvidia控制面板看不到,控制面板里没有,服务里也没有nvidia相关服务,但驱动已经安装了. 解决办法: 1.下载GeForce Experience并安装 . 2.通过GeFo ...

  4. grpc & pb 环境配置

    grpc 官方中文文档:http://doc.oschina.net/grpc?t=60140 grpc github仓库:https://github.com/grpc/grpc protobuf ...

  5. SNAT和DNAT

    1.SNAT iptables防火墙 Centos6.6 64位 iptables 内网:eth0 172.16.4.1 外网:eth 112.112.112.112/24 当有用户访问公网时,修改用 ...

  6. less初识

    一种 动态 样式 语言. LESS 将 CSS 赋予了动态语言的特性,如 变量, 继承,运算, 函数. LESS 既可以在 客户端 上运行 (支持IE 6+, Webkit, Firefox),也可以 ...

  7. stm32中assert_param的用法说明

    stm32中assert_param的用法说明   首先是要知道条件判断语句 这个运算符分成三部分: (条件) ? (条件成立执行部分) :(条件不成立执行部分) 就这么简单 例如:a=(x>y ...

  8. ubuntu系统中添加DNS服务器地址后诡异消失的解决办法

    今天查看了一下自己电脑里的ubuntu14.04系统,发现无法上网,于是ping了一下百度,出现unknown host,查了一下/etc/resolv.conf中的DNS地址,却发现我之前的修改被清 ...

  9. 【小程序】访问 https配置的数据接口

    小程序对于网络请求的URL的特殊要求:1)不能出现端口号;    2)不能用localhost;       3)  必须用https (一)搭建本地https服务器(windows) 搭建出来的服务 ...

  10. 复习整理2:juit

    @FixMethodOrder(MethodSorters.NAME_ASCENDING)测试回环 https://blog.csdn.net/u014294166/article/details/5 ...