PAT (Advanced Level) 1023. Have Fun with Numbers (20)
2024-08-26 14:05:14
手动模拟一下高精度加法。
#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 ;
}
最新文章
- GridView导出Excel(中文乱码)
- vue 2 滚动条加载更多数据实现
- subline 快捷键
- QRCode.jar生成二维码
- php循环创建目录
- theos的makefile写法
- ListView属性
- 利用Paramiko模块远程连接Linux
- 老李分享:loadrunner用javavuser进行接口测试
- 2017 多校训练 1002 Balala Power!
- DataBase MongoDB集群方案介绍
- MoonLight可视化订单需求区域分析系统前端
- Java虚拟机垃圾收集算法
- Python笔记-面向对象编程
- vue使用技巧(分页、nextTick、复制对象)
- Python 验证线程是数据共享的
- mysql 开发进阶篇系列 27 数据库字符集设置
- 洛谷 P2257 YY的GCD
- Spring ApplicationContext(六)BeanPostProcessor
- 宿主在Windows Service中的WCF(创建,安装,调用) (host到exe,非IIS)