pat 1023 Have Fun with Numbers(20 分)

时间:2021-08-24 22:40:46
1023 Have Fun with Numbers(20 分)

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 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 <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <stack>
#include <vector>
#include <queue>
#include <set>
#define LL long long
using namespace std;
const int MAX = ; long long A[] = {}, B[] = {}, len;
char s[MAX], s2[MAX];
bool is_equal()
{
for (int i = ; i <= ; ++ i)
if (A[i] != B[i]) return false;
return true;
} void calcS2()
{
int b = , temp[];
for (int i = , j = len - ; i < len; ++ i, -- j)
{
if (j != -) b += * (s[j] - '');
temp[i] = b % ;
b /= ;
if (b > && i == len - ) ++ len;
}
for (int i = , j = len - ; i < len; ++ i, -- j)
s2[j] = char('' + temp[i]);
} int main()
{
// freopen("Date1.txt", "r", stdin);
scanf("%s", &s);
len = strlen(s);
for (int i = ; i < len; ++ i)
A[s[i] - ''] ++;
calcS2();
len = strlen(s2);
for (int i = ; i < len; ++ i)
B[s2[i] - ''] ++;
if (is_equal()) cout <<"Yes" <<endl <<s2 <<endl;
else cout <<"No" <<endl <<s2 <<endl;
return ;
}

pat 1023 Have Fun with Numbers(20 分)的更多相关文章

  1. PAT &lpar;Advanced Level&rpar; Practice 1023 Have Fun with Numbers &lpar;20 分&rpar; 凌宸1642

    PAT (Advanced Level) Practice 1023 Have Fun with Numbers (20 分) 凌宸1642 题目描述: Notice that the number ...

  2. PAT 甲级 1023 Have Fun with Numbers &lpar;20 分&rpar;(permutation是全排列题目没读懂)

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

  3. 1023 Have Fun with Numbers &lpar;20 分&rpar;

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

  4. 【PAT甲级】1023 Have Fun with Numbers &lpar;20 分&rpar;

    题意: 输入一个不超过20位的正整数,问乘2以后是否和之前的数组排列相同(数字种类和出现的个数不变),输出Yes或No,并输出乘2后的数字. AAAAAccepted code: #define HA ...

  5. 【PAT甲级】1100 Mars Numbers &lpar;20 分&rpar;

    题意: 输入一个正整数N(<100),接着输入N组数据每组包括一行字符串,将其翻译为另一个星球的数字. AAAAAccepted code: #define HAVE_STRUCT_TIMESP ...

  6. PAT 甲级 1069 The Black Hole of Numbers &lpar;20 分&rpar;&lpar;内含别人string处理的精简代码&rpar;

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

  7. PAT 1023 Have Fun with Numbers&lbrack;大数乘法&rsqb;&lbrack;一般&rsqb;

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

  8. PAT &lpar;Advanced Level&rpar; Practice 1008 Elevator &lpar;20 分&rpar; 凌宸1642

    PAT (Advanced Level) Practice 1008 Elevator (20 分) 凌宸1642 题目描述: The highest building in our city has ...

  9. PAT甲级:1152 Google Recruitment &lpar;20分&rpar;

    PAT甲级:1152 Google Recruitment (20分) 题干 In July 2004, Google posted on a giant billboard along Highwa ...

  10. 1069 The Black Hole of Numbers &lpar;20分&rpar;

    1069 The Black Hole of Numbers (20分) 1. 题目 2. 思路 把输入的数字作为字符串,调用排序算法,求最大最小 3. 注意点 输入的数字的范围是(0, 104), ...

随机推荐

  1. ASP&period;NET弹出模态对话框【转】

    主页面 PageBase.aspx.cs 中的代码 protected void Page_Load(object sender, EventArgs e) {    if (!this.IsPost ...

  2. velocity的foreach下标

    velocity的foreach标签操作: #foreach( $per in ${list} ) #end 如果需要访问循环的当前目标的index可用通过${velocityCount},其默认是从 ...

  3. MySQL mysqlimport 从txt文件中导入数据到mysql数据库

    mysqlimport: 我说这个我们还是先从世界观方法论的高度来理解一下便有更加准确的把握.数据导入不外呼有两个部分 第一部分:目标对象--我们要把数据导给谁(mysqlimport 的目标对象自然 ...

  4. poj3237(树链剖分)

    题目链接:http://poj.org/problem?id=3237 题目大意:指定一颗树上有3个操作: 1)询问操作,询问a点和b点之间的路径上最长的那条边的长度(即最大值): 2)取反操作,将a ...

  5. 【原创】构建高性能ASP&period;NET站点 开篇

    原文:[原创]构建高性能ASP.NET站点 开篇 构建高性能ASP.NET站点 开篇 前言:有段时间没有写ASP.NET的东西了,心里总是觉得缺少了什么,毕竟自己对ASP.NET还是情有独钟的. 在本 ...

  6. C&num;算两个时间段相差的时间

    在数据中经常算两个时间差或者在某个时间段的内容 在数据库中设计表字段类型的时候设计为varchar类型,然后进行可以再Sql语句中书写>=或者<=这样的进行比较就可以查询出某个时间段的内容 ...

  7. OpenStack视图

    OpenStack视图 OpenStack视图是个全局资源的概念,统计了OpenStack所纳管资源的总量和使用量,因此OpenStack视图的资源通常又称为物理资源.OpenStack基于该资源使用 ...

  8. nohup 部署springboot 使用命令

    启动jar包:nohup java -jar news-0.0.1-SNAPSHOT.jar 查看进程:netstat -nap|grep  [3389]3389  为需要查看的端口号 关闭进程:ki ...

  9. 使用proxy来简单的实现一个观察者

    var obv = (function() { var cache = new Map(); var observe = function (proxy, fn) { if (!cache.has(p ...

  10. Leetcode-448&period; Find All Numbers Disappeared in an Array&lpar;solve without extra space easy&rpar;

    Given an array of integers where 1 ≤ a[i] ≤ n (n= size of array), some elements appear twice and oth ...