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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • RELU激活函数作用「建议收藏」

    RELU激活函数作用「建议收藏」梯度消失现象:在某些神经网络中,从后向前看,前面层梯度越来越小,后面的层比前面的层学习速率高。梯度消失原因:sigmoid函数导数图像导数最大为0.25&lt;1权重初始值通常使用一个高斯分布所以|w|&lt;1,所以wjσ′(zj)&lt;0.25,根据链式法则计算梯度越来越小。由于层数的增加,多个项相乘,势必就会导致不稳定的情况。sigmoid激活函数的…

    2022年6月16日
    36
  • vmware虚拟机文件_怎么往虚拟机里复制文件

    vmware虚拟机文件_怎么往虚拟机里复制文件VMware虚拟机文件(后缀)详解虚拟机的文件管理由VMwareWorkstation来执行,一个虚拟机一般以一系列文件的形式储存在宿主机中,这些文件一般在由workstation为虚拟机所创建的

    2022年8月2日
    16
  • pycharm创建python虚拟环境好处_pycharm虚拟环境与本地环境区别

    pycharm创建python虚拟环境好处_pycharm虚拟环境与本地环境区别提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档文章目录前言一、虚拟环境的作用二、虚拟环境的创建、查看以及删除1.虚拟环境的创建2.虚拟环境的查看3.虚拟环境的激活4.虚拟环境的删除总结前言网上的大多数教程都是通过使用第三方模块来创建和删除虚拟环境,对新手很不友好,在这里分享一下我使用Pycharm创建虚拟环境的过程。一、虚拟环境的作用每个虚拟环境中安装的第三方模块不会与其它环境中同名的第三方模块发生版本冲突,每个虚拟环境之间互不影响。通过为每个项目创建单独的虚拟环境

    2025年7月23日
    3
  • checkbox选中和不选中 jqu_jquery checkbox 选中不选中

    checkbox选中和不选中 jqu_jquery checkbox 选中不选中展开全部$(function(){//动态绑定默认状态//$(“#ck”).attr(“checked”,true)//选中//$(“#ck”).attr(“checked”,false)//未选中//点击判断选中还是未选中$(“#ck”).click(function(){if($(this).is(“:checked”)){alert(“选中”);}else{alert…

    2022年6月30日
    22
  • SQLServer 延迟事务持久性

    SQLServer 延迟事务持久性

    2021年11月26日
    47
  • 软件测试之因果图[通俗易懂]

    软件测试之因果图[通俗易懂]1.某软件规格说明书包含这样的要求:第一列字符必须是A或B,第二列字符必须是一个数字,在此情况下进行文件的修改,但如果第一列字符不正确,则给出信息L;如果第二列字符不是数字,则给出信息M。

    2022年8月14日
    6

发表回复

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

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