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 ...
随机推荐
- nginx配置错误
重启nginx:sudo /usr/local/nginx/sbin/nginx -s reload 出现错误提示:nginx: [emerg] unknown directive "if& ...
- 修改NavigationBar样式
iOS Tip: Change Status Bar Icon & Text Colors When iOS 7 was introduced Apple allowed your appli ...
- springsecurity源码查看网址
http://www.boyunjian.com/javasrc/org.springframework.security/spring-security-web/3.1.3.RELEASE/_/or ...
- GitHub这么火,程序员你不学学吗? 超简单入门教程 【转载】
本GitHub教程旨在能够帮助大家快速入门学习使用GitHub. 本文章由做全栈攻城狮-写代码也要读书,爱全栈,更爱生活.原创.如有转载,请注明出处. GitHub是什么? GitHub首先是个分布式 ...
- git 更新分支
git branch 本地分支 git branch test 创建分支 git pull origin fastboot 更新到最新版本 git branch -a 查看所有的分支,包括本地的和 ...
- Java学习笔记之基于TCP协议的socket
可以一直输入,而不是一问一答: 开两个线程,一个负责收,一个负责发. 1.先运行: package com.zr.javase0825; import java.io.BufferedReader; ...
- git 使用系列(二)---- 分支和合并
Branching and Merging The Git feature that really makes it stand apart from nearly every other SCM o ...
- 做.net的早晚会用到,并且网上还没有这方面的正确资料或几乎很少
原文网址:http://www.cnblogs.com/langu/archive/2012/03/23/2413990.html 一直以来,找安装程序的msi源文件路径得到的都是“system32” ...
- Android开机动画启动流程
android开机动画启动流程 从android的Surface Flinger服务启动分析知道,开机动画是在SurfaceFlinger实例通过调用startBootAnim()启动的. 下面我 ...
- ACM课程学习总结
ACM课程学习总结报告 通过一个学期的ACM课程的学习,我学习了到了许多算法方面的知识,感受到了算法知识的精彩与博大,以及算法在解决问题时的巨大作用.此篇ACM课程学习总结报告将从以下方面展开: 学习 ...