题目链接:http://www.patest.cn/contests/mooc-ds/00-%E8%87%AA%E6%B5%8B4

题面:

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, 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

题目大意:

就是问给定的一个数字乘以2之后,得到的新数字包括的每一个数字的个数是否与原数字包括的数量同样。题意是比較绕的。说什么乘二又乘二,又什么1-9。事实上。就是仅仅乘了1遍2。数字也能够包括0。数据是比較水的。这也是PAT比不上ACM的地方。网上一组仅仅数1-9的也过了。

解题:

由于数字有20位,long long也不够用。所以就自己手动模拟一下乘2的过程吧。

代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
using namespace std;
int main()
{
//计数。存储
int cnt1[10],cnt2[10],num1[25],num2[25],p=0,f=0,x;
string s;
bool flag=true;
memset(cnt1,0,sizeof(cnt1));
memset(cnt2,0,sizeof(cnt2));
memset(num1,0,sizeof(num1));
memset(num2,0,sizeof(num2));
//输入
cin>>s;
for(int i=s.length()-1;i>=0;i--)
{
num1[p++]=s[i]-'0';
}
//模拟乘2
for(int i=0;i<25;i++)
{
x=num1[i]*2+f;
num2[i]=x%10;
f=x/10;
}
//计数
for(int i=0;i<s.length();i++)
{
cnt1[num1[i]]++;
cnt2[num2[i]]++;
}
//特判最高位
if(num2[s.length()])cnt2[s.length()]++;
for(int i=0;i<10;i++)
if(cnt1[i]!=cnt2[i])
{
flag=false;
break;
}
//输出
if(flag)cout<<"Yes\n";
else cout<<"No\n";
flag=false;
//假设是0,那么p没有被赋值,输出0
p=0;
//去前导0
for(int i=24;i>=0;i--)
{
if(num2[i])
{
p=i;
break;
}
}
//输出
for(int i=p;i>=0;i--)
cout<<num2[i];
cout<<endl;
return 0;
}

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

  1. 中国大学MOOC-陈越、何钦铭-数据结构-2017春

    中国大学MOOC-陈越.何钦铭-数据结构-2017春 学习地址 详细学习内容 Github记录地址 欢迎fork和star,有惊喜值得学习! 参考学习笔记 参考AC代码 数据结构和算法学习笔记 学习内 ...

  2. 中国大学MOOC-陈越、何钦铭-数据结构-笔记

    中国大学MOOC-陈越.何钦铭-数据结构-2017春 跟着<中国大学MOOC-陈越.何钦铭-数据结构-2017春>学习,平时练习一下pat上的作业外:在这里记录一下:平时学习视屏的收获. ...

  3. 中国大学MOOC中的后台文件传输

    早期版本的中国大学MOOC一旦被挂起后,应用在完成当前下载任务后无法继续添加新任务,当然也无法将缓存状态写入数据库.这个问题能否顺利解决直接关系到用户体验. 顺便吐槽下,凡是使用了后台文件传输还提示你 ...

  4. 中国大学mooc直播回放看这里哦http://www.icourse163.org/forum/1001974001/topic-1003372881.htm?sortType=1&pageIndex=1

    中国大学mooc直播回放看这里哦http://www.icourse163.org/forum/1001974001/topic-1003372881.htm?sortType=1&pageI ...

  5. 中国大学MOOC课程信息之数据分析可视化二

    版权声明:本文为博主原创文章,转载 请注明出处:https://blog.csdn.net/sc2079/article/details/82318571 - 写在前面 本篇博客继续对中国大学MOOC ...

  6. 中国大学MOOC课程信息之数据分析可视化一

    版权声明:本文为博主原创文章,转载 请注明出处:https://blog.csdn.net/sc2079/article/details/82263391 9月2日更:中国大学MOOC课程信息之数据分 ...

  7. 中国大学MOOC课程信息爬取与数据存储

    版权声明:本文为博主原创文章,转载 请注明出处: https://blog.csdn.net/sc2079/article/details/82016583 10月18日更:MOOC课程信息D3.js ...

  8. 中国大学MOOC 邮箱验证的问题

    在使用 中国大学 MOOC 过程中,在PC端修改个人资料时,其中有项“常用邮箱”,于是写了QQ邮箱,结果发现一直无法验证,连邮件都无法收到. 经过多番尝试,重新使用邮箱注册的方式注册账号,然后注册成功 ...

  9. 【python】下载中国大学MOOC的视频

    [python]下载中国大学MOOC的视频 脚本目标: 输入课程id和cookie下载整个课程的视频文件,方便复习时候看 网站的反爬机制分析: 分析数据包的目的:找到获取m3u8文件的路径 1. 从第 ...

随机推荐

  1. Session原理、安全以及最基本的Express和Redis实现

    Session原理.安全以及最基本的Express和Redis实现 https://segmentfault.com/a/1190000002630691

  2. Kali linux 2016.2(Rolling)中metasploit的主机探测

    不多说,直接上干货! 1.活跃主机扫描 root@kali:~# ping -c 202.193.58.13 PING () bytes of data. bytes ttl= time=25.4 m ...

  3. 关于docker部署javaweb应用的问题

    我做了两个镜像,一个mysql,一个tomcat.建完mysql容器之后,在建tomcat的时候用--link把他们链接起来了进tomcat的容器里面 /etc/hosts 也发现了mysql的ip但 ...

  4. Ubuntu14.04下tensorflow安装

    自己电脑没装双系统,于是决定在虚拟机里装个tensorflow,以下是安装过程: 1.安装anaconda2 for Linux 官网下的话很慢,去清华的镜像网站下吧,我上一篇文章有网址 安装:bas ...

  5. 文本域内容在div中带换行显示

    function ReplaceSeperator(mobiles) { var i; var result = ""; var c; for (i = 0; i < mob ...

  6. MNIST手写数字数据集

    下载python源代码之后,使用: import input_data mnist = input_data.read_data_sets('MNIST_data/',one_hot=True) 下载 ...

  7. [JLOI2011]飞行路线 分层图最短路

    题目描述: Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在nn个城市设有业务,设这些城市分别标记为0到n-1,一共有m种航线,每种航线连接两个城市,并且航线有一 ...

  8. ubuntu18.04安装dash-to-dock出错的问题

    之前在安装dash-to-dock出现了这种错误: TypeError: ExtensionUtils.initTranslations is not a function Stack trace:i ...

  9. BEGINNING SHAREPOINT&#174; 2013 DEVELOPMENT 第9章节--client对象模型和REST APIs概览 JavaScript

    BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第9章节--client对象模型和REST APIs概览  JavaScript         与托管.NETclien ...

  10. POJ 1035-Spell checker(字符串)

    题目地址:POJ 1035 题意:输入一部字典.输入若干单词. 若某个单词能在字典中找到,则输出corret.若某个单词能通过 变换 或 删除 或 加入一个字符后.在字典中找得到.则输出这些单词.输出 ...