码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • PAT 1023 Have Fun with Numbers(高精度乘法)


    1023 Have Fun with Numbers

    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:

    1. Yes
    2. 2469135798

    2022.11.1(可能之前忘记写了) 

    代码:两次代码思路都是一样的

    1. //思路:先将原始出现的数字存储下来,然后将数字乘2(高精度乘法),最后判断2倍之后的数字是否
    2. //出现了和原始数字不同的数字
    3. #include
    4. #include
    5. using namespace std;
    6. vector<int> b(10);
    7. vector<int> mul(vector<int> &a,int b){
    8. vector<int> c;
    9. int t=0;
    10. for(int i=0;isize() || t;i++){
    11. t+=a[i]*b;
    12. c.push_back(t%10);
    13. t/=10;
    14. }
    15. //除前导0的情况是,0000*1234,结果为0000,那么需要除去前导0,变成0
    16. while(c.size()>1 && c.back()==0) c.pop_back();
    17. return c;
    18. }
    19. int main(){
    20. string s;
    21. vector<int> a;
    22. cin >> s;
    23. for(auto c:s) b[c-'0']++;//记录出现的数字
    24. for(int i=s.size()-1;i>=0;i--) a.push_back(s[i]-'0');
    25. auto c=mul(a,2);
    26. bool sign=false;
    27. for(auto q:c){
    28. b[q]--;
    29. if(b[q]<0){
    30. sign=true;
    31. break;
    32. }
    33. }
    34. if(!sign) puts("Yes");
    35. else puts("No");
    36. for(int i=c.size()-1;i>=0;i--) printf("%d",c[i]);
    37. return 0;
    38. }

     好好学习,天天向上!

    我要考研!

  • 相关阅读:
    2.1Java内存模型之JMM内存模型规范详解
    小啊呜产品读书笔记001:《邱岳的产品手记-12》第22讲 产品经理的图文基本功(上):产品文档 & 23讲产品经理的图文基本功(下):产品图例
    QT画图功能
    我做云原生的那几年
    性能问题从发现到优化一般思路
    机器学习之 Jupyter Notebook 使用
    【示波器专题】示波器探头不同的衰减比对测量的影响
    Android 修复在 Settings 首页,按键盘方向键逐个单选
    LeetCode高频题73. 矩阵置零
    pytorch faster_rcnn转为onnx格式
  • 原文地址:https://blog.csdn.net/weixin_50679551/article/details/127638741
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号