码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 1023 Have Fun with Numbers


    1023 Have Fun with Numbers

    0、题目

    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
    
    • 1

    Sample Output:

    Yes
    2469135798
    
    • 1
    • 2

    1、大致题意

    给出一个长度不超过20的整数,问这个整数两倍后的数位是否为原数位的一个排列。不管是yes还是no最后都要输出整数乘以2的结果

    2、基本思路

    简单题

    3、AC代码

    #include 
    #include 
    using namespace std;
    int book[10];
    int main() {
    	char num[22];
    	scanf("%s", num);
    	int flag = 0, len = strlen(num);
    	for(int i = len - 1; i >= 0; i--) {
    		int temp = num[i] - '0';
    		book[temp]++;
    		temp = temp * 2 + flag;
    		flag = 0;
    		if(temp >= 10) {
    			temp = temp - 10;
    			flag = 1;
    		}
    		num[i] = (temp + '0');
    		book[temp]--;
    	}
    	int flag1 = 0;
    	for(int i = 0; i < 10; i++) {
    		if(book[i] != 0)
    			flag1 = 1;
    	}
    	printf("%s", (flag == 1 || flag1 == 1) ? "No\n" : "Yes\n");
    	if(flag == 1) printf("1");
    	printf("%s", num);
    	return 0;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
  • 相关阅读:
    【05】Spring源码-手写篇-手写Bean配置
    扭蛋机小程序开发,互联网下的发展形式
    【校招VIP】前端HTML考察之meta标签相关
    工业锅炉设备监控该如何把握?
    【C++ 学习 ㉒】- 超详解 AVL 树的插入、平衡调整以及删除(含源代码)
    电机应用开发-PID控制器参数整定
    Docker中网络的使用和配置用法详解
    知识产权之围:跨境电商卖家的法律防线
    Node.js:pnpm - 速度快、节省磁盘空间的软件包管理器
    Mindspore网络构建
  • 原文地址:https://blog.csdn.net/qq_46371399/article/details/126410942
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | 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号