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. python正则表达式手记

    ----------re模块进行正则的使用---------- #result=re.match(正则表达式,要匹配的字符串):使用正则对字符串进行过滤从前面开始匹配#result.group():将 ...

  2. C语言运算符运算顺序判断实例2

    #include <stdio.h> int main(void) { , j = , k = ; printf("%d\n", ++i || ++j &&am ...

  3. Django models数据库配置以及多数据库联用设置

    今天来说说web框架Django怎么配置使用数据库,也就是传说中MVC(Model View Controller)中的M,Model(模型). 简单介绍一下Django中的MVC: 模型(model ...

  4. JUnit 3.8.1 源码学习

    JUnit 3.8.1 源码学习 环境搭建(源码加载配置) 由于IDE自身含有JUint插件,因此通过正常途径是没有源码加载入口的,因此需通过手动加载扩展JAR,然后再添加对应源码JAR,如图:项目右 ...

  5. 转:H2 入门

    H2 Database做为轻量级的内嵌数据库,功能十分强大,而且运行时只需要一个jar包即可,下表是官网的描述: 更详细的对比见官网页面: http://www.h2database.com/html ...

  6. java四则运算生成器

    题目描述: 从<构建之法>第一章的 "程序" 例子出发,像阿超那样,花二十分钟写一个能自动生成小学四则运算题目的命令行 "软件",满足以下需求: 除 ...

  7. 201521123070 《JAVA程序设计》第5周学习总结

    1. 本章学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. http://naotu.baidu.com/file/02b01f465e125c5942648a03358273b0 2. ...

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

    1. 本周学习总结 初学面向对象,会学习到很多碎片化的概念与知识.尝试学会使用思维导图将这些碎片化的概念.知识组织起来.请使用纸笔或者下面的工具画出本周学习到的知识点.截图或者拍照上传. 本周学习总结 ...

  9. 201521123030 《Java程序设计》 第11周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 1.互斥访问与同步访问 完成题集4-4(互斥访问)与4-5(同步访问) ...

  10. HashMap、HashTable、ArrayList、LinkedList、Vector区别

    HashTable和HashMap区别 ①继承不同. public class Hashtable extends Dictionary implements Map public class Has ...