当前位置: 首页 > news >正文

1023 Have Fun with Numbers

1023 Have Fun with Numbers
分数 20

全屏浏览

切换布局
作者 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 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

1.分析

        1.20位数字,用字符串进行运算。

        2.数字标记出现数字的次数,a中出现加一,b中出现减一。最后判断是否为0即可。

2.代码

#include<iostream>
#include<vector>
using namespace std;
string a,b;
vector<int> v;
int idx[12],t;
bool check(){          //判断for(int i=0;i<10;i++){if(idx[i]!=0) return false;}return true;
}
int main(){cin>>a;for(int i=0;i<a.size();i++){     //标记aidx[a[i]-'0']++;}for(int i=a.size()-1;~i;i--){    //计数bt+=(a[i]-'0')*2;            //进位加法idx[t%10]--;v.push_back(t%10);        //存储t/=10;}if(t!=0) idx[t]--,v.push_back(t);if(check()) cout<<"Yes"<<endl;else cout<<"No"<<endl;for(int i=v.size()-1;i>=0;i--){   //输出cout<<v[i];}return 0;
}

相关文章:

  • Python基础语法——常量变量
  • 【Linux】进程的程序替换、自定义shell命令行解释器
  • 批量将多个文件按扩展名分类到不同文件夹
  • 如何实现动态请求地址(baseURL)
  • 数据库案例1--视图和索引
  • lvs + keepalived + dns 高可用
  • 嵌入式开发
  • 实时数据同步方案
  • 网络安全·第四天·扫描工具Nmap的运用
  • libaom 码率控制实验:从理论到实践的深度探索
  • 水污染治理(生物膜+机器学习)
  • Android离屏渲染
  • ubuntu 常用指令
  • leetcode298.生命游戏
  • E-trace for risc-v
  • 机器视觉检测Pin针歪斜应用
  • 编写了一个专门供强化学习玩的贪吃蛇小游戏,可以作为后续学习的playgraound
  • L1-028 判断素数
  • Python asyncio 入门实战-2
  • 游戏引擎学习第226天
  • 耶路撒冷发生山火,以防长宣布紧急状态
  • 剑指3000亿产业规模,机器人“武林大会”背后的无锡“野望”
  • “上报集团文化助力区域高质量发展赋能平台”揭牌
  • 第二十届中国电影华表奖揭晓!完整获奖名单来了
  • 上海市市管干部任职前公示:赵亮拟为地区区长人选
  • 2025上海浪琴环球马术冠军赛开赛在即,首批赛马今晨抵沪