码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • C. Minimum Varied Number


    time limit per test

    1 second

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    Find the minimum number with the given sum of digits ss such that all digits in it are distinct (i.e. all digits are unique).

    For example, if s=20s=20, then the answer is 389389. This is the minimum number in which all digits are different and the sum of the digits is 2020 (3+8+9=203+8+9=20).

    For the given ss print the required number.

    Input

    The first line contains an integer tt (1≤t≤451≤t≤45) — the number of test cases.

    Each test case is specified by a line that contains the only integer ss (1≤s≤451≤s≤45).

    Output

    Print tt integers — the answers to the given test cases.

    Example

    input

    Copy

     
    

    4

    20

    8

    45

    10

    output

    Copy

    389
    8
    123456789
    19
    

    解题说明:此题要求数字不重复,n小于10直接输出就行,大于10是先让n从9开始逐一减,直到n满足要求。

    1. #include
    2. int main()
    3. {
    4. int t, n, digit;
    5. scanf("%d", &t);
    6. while (t--)
    7. {
    8. scanf("%d", &n);
    9. if (n < 10)
    10. {
    11. printf("%d\n", n);
    12. continue;
    13. }
    14. digit = 9;
    15. while (n > digit)
    16. {
    17. n -= digit;
    18. digit--;
    19. }
    20. printf("%d", n);
    21. digit++;
    22. while (digit < 10)
    23. {
    24. printf("%d", digit++);
    25. }
    26. printf("\n");
    27. }
    28. return 0;
    29. }

  • 相关阅读:
    服务器(Windows系统)自建filebrowser网盘服务器超详细教程
    Kafka: Windows环境-单机部署和伪集群、集群部署
    Vue:watch的多种使用方法
    010:连续跌3天,同时这三天收盘价都在20日均线下,第四天上涨的概率--以京泉华为例
    ARM的七种工作模式
    MongoDB 中的 push 操作(将文档插入到数组中)
    探索以太坊 Layer 2 解决方案的后起之秀——Starknet
    【MySQL | 运维篇】02、MySQL 主从复制
    【机器学习】GBDT (Gradient Boosting Decision Tree) 深入解析
    最新ChatGPT程序源码+AI系统+详细图文部署教程/支持GPT4.0/支持Midjourney绘画/Prompt知识库
  • 原文地址:https://blog.csdn.net/jj12345jj198999/article/details/126580236
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | 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号