Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we will obtain 246913578, which happens to be another 9-digit number consisting exactly the numbers from 1 to 9, only in a different permutation. Check to see the result if we double it again!

Now you are suppose to check if there are more numbers with this property. That is, double a given number with kk digits, you are to tell if the resulting number consists of only a permutation of the digits in the original number.

Input Specification:

Each input contains one test case. Each case contains one positive integer with no more than 20 digits.

Output Specification:

For each test case, first print in a line "Yes" if doubling the input number gives a number that consists of only a permutation of the digits in the original number, or "No" if not. Then in the next line, print the doubled number.

Sample Input:

1234567899

Sample Output:

Yes
2469135798
说明:最开始使用的思路是大数计算的方式,存入字符串数组,然后运算后与原数组进行对比,但存在wa点,现在没找到。先放置于此:
#include <stdio.h>
#include<string.h>
int main()
{
// N为长度,M为进位
int N = ,M = , i = , num = ,loop = , j = ;
char str[];
char tmp[];
scanf("%s",str);
N = strlen(str); for(i = N - ; i >= ; i--){
num = (str[i] - '')* + M;
M = ;
if(num > ){
num = num % ;
M++;
}
tmp[i] = num + '';
}
for(i = ; i < N; i++){
for(j = ; j < N; j++){
if(tmp[i] == str[j]){
str[j] = 'a';
break;
}
}
}
for(i = ; i < N; i++){
if(str[i] != 'a'){
loop = ;
break;
}
}
if(M == ){
printf("No\n1");
for(i = ; i < N; i++){
printf("%d",tmp[i] - '');
}
return ;
}
if(loop == ){
for(i = ; i < N; i++){
printf("%d",tmp[i] - '');
}
}else{
printf("Yes\n");
for(i = ; i < N; i++){
printf("%d",tmp[i] - '');
}
}
return ;
}

后改变思路,只记录0~9十个数组出现的次数,仅需要两个长度为10的一维数组即可。使用别人写的C++代码,引用链接在最后

 #include <cstdio>
#include <string>
#include <iostream>
using namespace std;
int cnt1[] = { }, cnt2[] = {}; int main(){
string s;
cin >> s;
string s2 = s;
for (int i = ; i < s.size(); i++){
cnt1[s[i] - '']++;
}
int carry = ;
for (int i = s.size() - ; i >= ; i--){
s2[i] = ((s[i] - '') * + carry )% + '';
carry = ((s[i] - '') * + carry) / ;
}
if (carry){
char c = carry + '';
s2 = c + s2;
cout << "No\n" << s2 << endl;
return ;
}
for (int i = ; i < s2.size(); i++){
cnt2[s2[i] - '']++;
}
bool flag = true;
for (int i = ; i < ; i++){
if (cnt1[i] != cnt2[i]){
flag = false;
break;
}
}
if (flag) cout << "Yes" << "\n" << s2 << endl;
else cout << "No\n" << s2;
return ;
}

http://blog.csdn.net/xtzmm1215/article/details/38837203

自测-4 Have Fun with Numbers的更多相关文章

  1. pat00-自测4. Have Fun with Numbers (20)

    00-自测4. Have Fun with Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yu ...

  2. 数据结构练习 00-自测4. Have Fun with Numbers (20)

    Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, wit ...

  3. 00-自测4. Have Fun with Numbers

    Notice that the number 123456789 is a 9-digit number consisting exactly the numbers from 1 to 9, wit ...

  4. PTA 自测-4 Have Fun with Numbers

    #include<iostream> #include<string> #include<cstring> #include<vector> using ...

  5. PAT自测_打印沙漏、素数对猜想、数组元素循环右移、数字加倍重排、机器洗牌

    -自测1. 打印沙漏() 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个“*”,要求按下列格式打印 ***** *** * *** ***** 所谓“沙漏形状”,是指每行输出奇数个符号 ...

  6. poj 3641 Pseudoprime numbers Miller_Rabin测素裸题

    题目链接 题意:题目定义了Carmichael Numbers 即 a^p % p = a.并且p不是素数.之后输入p,a问p是否为Carmichael Numbers? 坑点:先是各种RE,因为po ...

  7. jmeter压测数据库,抓包工具,python基础

    jmeter压力测试 前提场景的设置:单场景(单个接口进行压力测试一个请求)或混合场景(有业务流程的场景进行压力测试多个请求),压测时间一般在5--1515分组具体看需求. 数据准备:数据量少和数据量 ...

  8. 【MySQL】sysbench压测服务器及结果解读

    主要压测范围包括CPU测试.磁盘IO测试.线程测试.OLTP测试等,那么sysbench就可以满足我们的压测需求.下面我们简单来看下sysbench的安装使用以及压测结果的解读. 一.sysbench ...

  9. pat00-自测5. Shuffling Machine (20)

    00-自测5. Shuffling Machine (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue Sh ...

随机推荐

  1. AVAssetWriter 硬编码bug解决

    一.需求 直播助手在录屏过程中,产品要求跟随用户手机屏幕旋转,录屏的视频跟随旋转 二.实施方案 目前触手录,iTools PC端均已经实现该功能,并且该功能只适配iOS9和iOS10系统.猜测实现方案 ...

  2. 快速排序/快速查找(第k个, 前k个问题)

    //快速排序:Partition分割函数,三数中值分割 bool g_bInvalidInput = false; int median3(int* data, int start, int end) ...

  3. Android studio 1.x 安装完毕后无法打开问题解决方案

    Android Studio 1.0正式发布,给Android开发者带来了不小的惊喜,再也不用为繁琐的环境配置而烦恼,从某一层面上说这降低了android开发门槛. 不过貌似只能开心一会儿,因为and ...

  4. 安装mariadb二进制程序

    author:JevonWei 版权声明:原创作品 下载mariadb软件包 https://downloads.mariadb.org/mariadb/5.5.57/ 一.创建用户和准备数据目录 1 ...

  5. hdu 3342 拓扑排序 水

    好久没切题  先上水题! 拓扑排序! 代码: #include<iostream> #include<cstdio> #include<cstring> using ...

  6. Project 7:自然数的拆分

    自然数的拆分:任何一个大于1的自然数N,总可以拆分成若干个自然数之和,并且有多种拆分方法.例如自然数5,可以有如下一些拆分方法: 5=1+1+1+1+1 5=1+1+1+2 5=1+2+2 5=1+4 ...

  7. 第二次项目冲刺(Beta阶段)第一天

    a. 安排连续七天的敏捷冲刺. 2017.5.18完成冲刺计划安排 2017.5.20完善主页面 1st day(目前位置) 2017.5.21完善功能 2st day 2017.5.22添加自定义重 ...

  8. 201521145048 《Java程序设计》第3周学习总结

    1. 本章学习总结 学会了对于一个基本类的创建,需要有属性(private public protected),方法( 静态方法 非静态方法),构造函数,main函数,在定义属性时一般使用privat ...

  9. 201521123050《Java程序设计》第1周学习总结

    1. 本周学习总结 java至今已经不仅是个程序语言,也代表了解决问题的平台,更代表原厂,各个厂商,社群,开发者与用户沟通的成果.若以程序语言来看待java,正如冰山一角,如此便看不到java身为程序 ...

  10. 201521123072《java程序设计》第十四周学习总结

    201521123072<java程序设计>第十四周学习总结 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多数据库相关内容. 2. 书面作业 1. MySQL数据库 ...