题目链接: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. 查看spark是否有僵尸进程,有的话,先杀掉。可以使用下面命令

    查看spark是否有僵尸进程,有的话,先杀掉.可以使用下面命令yarn application -listyarn application -kill <jobid>

  2. String slices

    String slices A segment of a string is called a slice. Selecting a slice is similar selecting a char ...

  3. spring boot 集成 mybatis,数据库为mysql

    导入mven工程即可运行,方法不描述了,具体见 https://github.com/davidwang456/spring-boot-mybatis-demo

  4. Webkit 的麻烦和解决

    * placeholder 在 focus 状态下内容为空时,依然显示文字.和 IE11,Firefox 均不一致: input:focus::-webkit-input-placeholder { ...

  5. php 自带加密函数 mcrypt_encrypt

    <?php /** * AES128加解密类 * @author dy * */ class Aes{ //密钥 private $_secrect_key; public function _ ...

  6. 解决zabbix容器中文无法选择的问题

    1.查看zabbiz-web运行的容器 2.进入容器 3.安装语言包(针对centos7) yum install -y kde-l10n-chinese 4.更新gitbc包(因为镜像阉割了该包的部 ...

  7. jumpserver 新建用户收不到邮件

    在设置邮件开启pop3/smtp/imap 时 会提示要设置授权码 重启jumpserver 遇到错误  163 邮箱没有收到密码 点击更新没有效果 测试连接成功以后 ,删除用户 ,然后 重新 创建一 ...

  8. hdu 6363 bookshelf

    题解讲的很清楚了,直接看代码就懂了 题解:http://bestcoder.hdu.edu.cn/blog/2018-multi-university-training-contest-6-solut ...

  9. unity C# 获取有关文件、文件夹和驱动器的信息

    class FileSysInfo { static void Main() { // You can also use System.Environment.GetLogicalDrives to ...

  10. Android如何从外部跳进App

    博客出自:http://blog.csdn.net/liuxian13183,转载注明出处! All Rights Reserved ! 这个问题解决了两天时间,因为网上没有完整的解决方案,解决后分享 ...