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. iOS 微信支付流程详解

    背景 自微信支付.支付宝支付入世以来,移动端的支付日渐火热.虚拟货币有取代实体货币的趋向(这句纯属扯淡,不用管),支付在app开发中是一项基本的功能,有必要去掌握.从难易程度上讲,不管是微信支付还是支 ...

  2. C# 三层架构之系统的登录验证与添加数据的实现

    利用三层架构体系,实现学生管理系统中用户的登录与添加班级信息的功能,一下代码为具体实现步骤的拆分过程: 一.用户登录界面功能的实现 1.在数据访问层(LoginDAL)进行对数据库中数据的访问操作 u ...

  3. Linux的vi常用命令详解

    1.vi的基本概念  基本上vi可以分为三种状态,分别是命令模式(command mode).插入模式(Insert mode)和底行模式(last line mode),各模式的功能区分如下:   ...

  4. C++中const关键字用法

    为什么使用const?采用符号常量写出的代码更容易维护:指针常常是边读边移动,而不是边写边移动:许多函数参数是只读不写的.const最常见用途是作为数组的界和switch分情况标号(也可以用枚举符代替 ...

  5. windows系统,优化C盘空间的方法

    C盘在使用过程中,内容会越来越多,剩余空间越来越小.如何清理出更多空间呢?以windows7为例 转载请保留 http://www.cnblogs.com/lion-zheng/ cleanmgr w ...

  6. MSH:一个简单SH工具实现

    本文将分为不同的Part,分别实现Shell的一部分功能. msh从CSAPP的SHLAB出发,逐渐完善SHELL功能,并移植到自己的OS上. Github: https://github.com/H ...

  7. 201521123082 《Java程序设计》第14周学习总结

    201521123082 <Java程序设计>第14周学习总结 标签(空格分隔):java 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多数据库相关内容. Answ ...

  8. GUI(自定义背景图片)

    如果组件中没有setIcon(...);这个方法,这是有需要给组件设置背景图片,这时就可以自定义绘制背景图片 /** * */ package com.niit.javagui; import jav ...

  9. 团队作业9——Beta版本展示博客

    一. 骆杰宁(组长) 风格:少说话,多做事. 擅长技术:Jsp 编程兴趣:GUI 希望角色:PM 一句话宣言:年轻是本钱,不努力就不值钱. 胡丹丹 风格:不断沉淀自己 擅长技术:擅长TCP/IP协议模 ...

  10. 201521123071 《JAVA程序设计》第七周学习总结

    第7周-集合 1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 1.1 Iterator<E> iterator(); //iterator()返回一个实现了It ...