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

时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue

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 k 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 file 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

提交代码

 #include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <cmath>
#include <iostream>
using namespace std;
int ti[],num1[],num2[];
char num[];
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
scanf("%s",num); //cout<<num<<endl; int i;
for(i=;i<strlen(num);i++){
num1[i]=num[i]-'';
ti[num1[i]]++;
num2[i]=*num1[i];
}
int k=,t;
for(i=strlen(num)-;i>=;i--){
t=num2[i]+k;
num2[i]=t%;
ti[num2[i]]--;
k=t/;
}
bool can=false;
if(!k){
for(i=;i<=;i++){
if(ti[i]){
break;
}
}
if(i==){
can=true;
}
}
if(can){
printf("Yes\n");
}
else{
printf("No\n");
}
if(k){
printf("%d",k);
}
for(i=;i<strlen(num);i++){
printf("%d",num2[i]);
}
printf("\n");
return ;
}

pat00-自测4. Have Fun with Numbers (20)的更多相关文章

  1. 数据结构练习 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 ...

  2. How to Pronounce Numbers 20 – 1 Billion

    How to Pronounce Numbers 20 – 1 Billion Share Tweet Share Tagged With: Numbers Numbers are something ...

  3. PAT甲级 1120. Friend Numbers (20)

    1120. Friend Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Two in ...

  4. pat1100. Mars Numbers (20)

    1100. Mars Numbers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue People o ...

  5. pat1069. The Black Hole of Numbers (20)

    1069. The Black Hole of Numbers (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, ...

  6. PAT-中国大学MOOC-陈越、何钦铭-数据结构基础习题集 00-自測4. Have Fun with Numbers (20) 【二星级】

    题目链接:http://www.patest.cn/contests/mooc-ds/00-%E8%87%AA%E6%B5%8B4 题面: 00-自測4. Have Fun with Numbers ...

  7. 1069. The Black Hole of Numbers (20)【模拟】——PAT (Advanced Level) Practise

    题目信息 1069. The Black Hole of Numbers (20) 时间限制100 ms 内存限制65536 kB 代码长度限制16000 B For any 4-digit inte ...

  8. PAT 甲级 1069 The Black Hole of Numbers (20 分)(内含别人string处理的精简代码)

    1069 The Black Hole of Numbers (20 分)   For any 4-digit integer except the ones with all the digits ...

  9. PAT 甲级 1023 Have Fun with Numbers (20 分)(permutation是全排列题目没读懂)

    1023 Have Fun with Numbers (20 分)   Notice that the number 123456789 is a 9-digit number consisting ...

随机推荐

  1. It企业的上市与退市

    目前我国的it上市公司有同方股份.华胜天成.长城电脑.航天信息.用友软件.中国软件.东软集团.长电科技.华东科技.航天长峰.航天科技.士兰微.上海贝岭等等. 一般来讲公司上市是为了融资,一是为了解决资 ...

  2. SourceTree使用

    SourceTree的基本使用   1. SourceTree是什么 拥有可视化界面的项目版本控制软件,适用于git项目管理 window.mac可用 2. 获取项目代码 1. 点击克隆/新建 2. ...

  3. angular 父组件调用子组件

    import { Component, OnInit, ViewChild } from '@angular/core'; @Component({ selector: 'app-child', te ...

  4. rsync 备份服务搭建(完成)

    rsync服务守护进程 服务器端配置过程: 1. 检查rsync是否安装: rpm -qa rsync 2.添加rsync服务的用户,管理本地目录 useradd-s /sbin/nologin -M ...

  5. 如何解决diff: /../Podfile.lock: No such file or directory 的问题

    1.问题描述 之前碰到过此类问题,原因是之前用了测试版本的pod,然后回归正式版本,导致找不到pod文件 diff: /../Podfile.lock: No such file or directo ...

  6. 洛谷P4526 【模板】自适应辛普森法2(Simpson法)

    题面 传送门 题解 据说这函数在\(x>15\)的时候趋近于\(0\) 据说当且仅当\(a<0\)时积分发散 所以直接套自适应\(simpson\)吧-- //minamoto #incl ...

  7. 在libuv中使用openssl建立ssl连接

    在libuv中使用openssl建立ssl连接 @(blogs) 使用openssl进行加密通信时,通常是先建立socket连接,然后使用SSL_XXX系列函数在普通socket之上建立安全连接,然后 ...

  8. Linux原理与实践

    Linux 中的文件及权限 -rwxr-xr-x 1 cat animal 68 03-31 21:47 sleep.sh 三种用户角色: r 4 w 2 x 1 user ,文件的所有者 group ...

  9. Reviewing notes 1.1 of Advanced algebra

    ♦Linear map Definition Linear map A linear map from vector space V to W over a field F is a function ...

  10. [I/O]一览图