hdu2544_GB4278

hdu2544_GB4278HDU 4278 Faulty Odometer

大家好,又见面了,我是你们的朋友全栈君。

Faulty Odometer

http://acm.hdu.edu.cn/showproblem.php?pid=4278

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 725    Accepted Submission(s): 512

Problem Description
  You are given a car odometer which displays the miles traveled as an integer. The odometer has a defect, however: it proceeds from the digit 2 to the digit 4 and from the digit 7 to the digit 9, always skipping over the digit 3 and 8. This defect shows up in all positions (the one’s, the ten’s, the hundred’s, etc.). For example, if the odometer displays 15229 and the car travels one mile, odometer reading changes to 15240 (instead of 15230).
 
Input
  Each line of input contains a positive integer in the range 1..999999999 which represents an odometer reading. (Leading zeros will not appear in the input.) The end of input is indicated by a line containing a single 0. You may assume that no odometer reading will contain the digit 3 and 8.
 
Output
  Each line of input will produce exactly one line of output, which will contain: the odometer reading from the input, a colon, one blank space, and the actual number of miles traveled by the car.
 
Sample Input
 
15
2005
250
1500
999999
0

 
Sample Output
 
15: 12
2005: 1028
250: 160
1500: 768
999999: 262143

 
Source
 
Recommend
liuyiding
 
 
类似于8进制转化为10进制
 
#include<stdio.h>

int num[20],cnt;

void change(int x){
    cnt=0;
    while(x){
        num[cnt++]=x%10;
        x/=10;
    }
    for(int i=0;i<cnt;i++)
        if(num[i]>=9)
            num[i]-=2;
        else if(num[i]>=4)
            num[i]-=1;
}

int main(){
    int n;
    while(scanf("%d",&n) && n){
        int ans=0;
        change(n);
        for(int i=cnt-1;i>=0;i--)
            ans=ans*8+num[i];
        printf("%d: %d\n",n,ans);
    }
    return 0;
}

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/107096.html原文链接:https://javaforall.net

(0)
上一篇 2022年4月21日 上午10:20
下一篇 2022年4月21日 上午10:20


相关推荐

  • python调用matplotlib报错_pycharm没有matplotlib模块

    python调用matplotlib报错_pycharm没有matplotlib模块【Pycharm第二天】matplotlib安装不了?问题来了,一招搞定!

    2022年8月29日
    4
  • 处理js乱码

    处理js乱码1.将time.js编码格式更改外2.在Tomcat设置VM-OPTION选项为-Dfile.encoding=utf-8

    2022年6月12日
    45
  • mysql 唯一索引_mysql主键和唯一索引的区别

    mysql 唯一索引_mysql主键和唯一索引的区别Mysql索引大概有五种类型:普通索引(INDEX):最基本的索引,没有任何限制唯一索引(UNIQUE):与”普通索引”类似,不同的就是:索引列的值必须唯一,但允许有空值。主键索引(PRIMARY):它是一种特殊的唯一索引,不允许有空值。全文索引(FULLTEXT):可用于MyISAM表,mysql5.6之后也可用于innodb表,用于在一篇文章中,检索文本信息的,针对较大的数据,生成全文索引很耗时和空间。联合(组合)索引:为了更多的提高mysql效率可建立组合索引,遵循”最左前缀“原

    2026年1月31日
    3
  • 并发编程面试题(2020最新版)「建议收藏」

    文章目录基础知识并发编程的优缺点为什么要使用并发编程(并发编程的优点)并发编程有什么缺点并发编程三要素是什么?在Java程序中怎么保证多线程的运行安全?并行和并发有什么区别?什么是多线程,多线程的优劣?线程和进程区别什么是线程和进程?进程与线程的区别什么是上下文切换?守护线程和用户线程有什么区别呢?如何在Windows和Linux上查找哪个线程cpu利用率最高?什么是线程死锁形成死锁的…

    2022年4月18日
    42
  • IDEA导入Eclipse项目

    IDEA导入Eclipse项目背景 用习惯了 idea 再去用 eclipse 实在用的不习惯 于是将老的 eclipse 项目导入到 eclipse 网上有很多教程 看了很多博客都不行 一直报错 各种报错 现在终于好了 我们一起来看看怎么将 eclipse 的项目导入到 idea1 新建一个文件夹 idea 打开这个空文件夹 2 将项目导入 3 窗口右下角等待项目编译完成 4 配置项目环境和结构注意 上面的

    2026年3月26日
    3
  • 机构:关注AI算力产业链相关投资机遇

    机构:关注AI算力产业链相关投资机遇

    2026年3月13日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号