手动模拟一下高精度加法。

#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)的更多相关文章

  1. 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 ...

  2. PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642

    PAT (Advanced Level) Practice 1019 General Palindromic Number (20 分) 凌宸1642 题目描述: A number that will ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. 安卓OpenGL入门

    1.先用一个GLSurfaceView作为画布,然后自定义一个Renderer继承自Renderer,把这个自定义的Renderer通过setRenderer()设置给GLSurfaceView就可以 ...

  2. 制作 macOS Sierra 正式版U盘USB启动安装盘方法教程 (全新安装 Mac 系统)

    使用命令行创建制作 macOS Sierra 正式版 USB 安装盘 1.准备一个 8GB 或更大容量的 U盘,并备份好里面的所有资料. 2.下载好 macOS Sierra 正式版的安装程序(app ...

  3. CentOS6.6 部署Apache+Svn

    svn代码 目前大多数公司 管理代码都是用这个 这个比较方便简单,git用的人数也比较多,我们下面来部署一下这个程序 svn+apache集成 系统环境 # cat /etc/redhat-relea ...

  4. python socketserver实现客户端多并发

    直接看代码 server #!/usr/bin/env python # -*- coding:utf-8 -*- import socketserver import subprocess clas ...

  5. js监听键盘方向键事件

    <SCRIPT language=javascript> document.onkeydown = chang_page; function chang_page() { || ) loc ...

  6. iOS 10推送通知开发

    原文地址:Developing Push Notifications for iOS 10,译者:李剑飞 虽然通知经常被过度使用,但是通知确实是一种获得用户关注和通知他们需要更新或行动的有效方式.iO ...

  7. JS-加载页面的时候自动选择刚才所选择option

    <body class="no-skin" onload="option_auto(${pd.PACK_SORT})"> <select na ...

  8. java模式:模板模式的简单理解

    1.模板模式就是用虚类作为基类将几个要执行差不多操作中相同的部分提取出来,不同的部分各自实现! 2.下面给出简单栗子: 我要进行的操作是将大象和狐狸放入冰箱,放入大象和狐狸有相同的步骤:开冰箱和关冰箱 ...

  9. windows下python+Django+eclipse开发环境的配置

    1.JDK环境的安装 在http://www.java.com/zh_CN/download/faq/develop.xml 页面下,点击JDK下载,下载所需的jdk版本.直接点击安装即可. 2.py ...

  10. publish over ssh

    http://stackoverflow.com/questions/22158092/jenkins-transferring-0-files-using-publish-over-ssh-plug ...