https://pintia.cn/problem-sets/994805342720868352/problems/994805478658260992

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

题解: long long 会爆掉 所以字符串模拟加法
代码:
#include <cstdio>
#include <string>
#include <stack>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std; char s[2222], num[2222], sum[2222], c, summ[2222]; int main() {
scanf("%s", s);
int dot = 0;
bool flag = true;
int len = strlen(s);
int k = 0, ans = 0;
for(int i = len - 1; i >= 0; i--) {
sum[ans++] = '0' + (s[i] - '0' + s[i] - '0' + k) % 10;
k = (s[i] - '0' + s[i] - '0' + k) / 10;
}
if(k) {
sum[ans++] = '1';
flag = 0;
}
for(int i = 0; i <= ans / 2 - 1; i++)
swap(sum[i], sum[ans - i - 1]);
strcpy(summ, sum);
sort(s, s + len);
sort(summ, summ + ans);
if(strcmp(s, summ) != 0) flag = 0;
if(flag) printf("Yes\n");
else printf("No\n");
printf("%s\n", sum);
return 0;
}

  

最新文章

  1. MySql.Data.Entity 在EF中解析uint的枚举时有BUG
  2. 如何判断Javascript对象是否存在
  3. 在jQuery代码中,实现转跳
  4. Python基础之【第二篇】
  5. CPU工作状态的知识介绍
  6. Sqlserver中存储过程,触发器,自定义函数
  7. Eclipse for PHP Developers + xamp +xdebug
  8. 任意轴算法 ( Arbitrary Axis Algorithm )
  9. C#多态及接口
  10. H264-YUV通过RTP接收视频流ffmpeg解码SDL实时播放
  11. 题解-SDOI2015 约数个数和
  12. Js -----后台json数据,前端生成下载text文件
  13. JS_高程5.引用类型(3)Array类型-检测数组
  14. AltiumDesigner PCB中栅格与格点的切换
  15. leetcode — merge-k-sorted-lists
  16. wireshark显示过滤器的几种用法(转自他人博客)
  17. 学习笔记之MobaXterm
  18. js 验证input 输入框
  19. hdu 5248 贪心
  20. js 小数取整,js 小数向上取整,js小数向下取整

热门文章

  1. 学习python的一些脚本
  2. Go语言中结构体的使用-第1部分结构体
  3. kaggle之员工离职分析
  4. 20155231 cho2 课下作业
  5. 20155302 《Java程序设计》实验一(Java开发环境的熟悉)实验报告
  6. 【MongoDB】NoSQL Manager for MongoDB 教程(基础篇)
  7. 【SQLSERVER】递归查询算法实例
  8. Drupal7 针对特定条件才显示区块
  9. javaweb(三十一)——国际化(i18n)
  10. 3.5星|《算法霸权》:AI、算法、大数据在美国的阴暗面