zoukankan      html  css  js  c++  java
  • NYOJ506 洗澡

     

    洗澡

    时间限制:1000 ms  |  内存限制:65535 KB
    难度:1
     
    描述

    Mostrp是个爱干净的好少年。 有一次去澡堂洗澡时发现 澡堂的澡柜编号中没有出现过数字‘4’。 Mostrp 感到很好奇。可能是因为在澡堂老板眼里。数字‘4’是十分不吉利的。

    现在Mostrp知道澡柜的最大的编号N,你能帮他算出澡堂一共有多少澡柜吗?

     
    输入
    有多组数据,每行输入一个N。
    ( 1 <= N <= 50000 )
    输出
    输出澡柜的个数,输出占一行。
    样例输入
    3
    5
    样例输出
    3
    4

    起来水一题 。。。。
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <iostream>
    
    using namespace std;
    
    int fun(char* s)
    {
        int tot = 0;
        int len = strlen(s);
        for(int i = 0; i < len; ++i)
        {
            int cnt = s[i] - '0';
            if(s[i] > '4')
                --cnt;
            tot += cnt * (int)pow(9,len - i -1);
        }
        return tot;
    }
    
    int main()
    {
        char s[10];
        while(cin >> s)
        {
            cout << fun(s) << endl;
        }
        return 0;
    }
    
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <iostream>
    
    using namespace std;
    
    int fun(char* s)
    {
        int tot = 0;
        int len = strlen(s);
        for(int i = 0; i < len; ++i)
        {
            int cnt = s[i] - '0';
            if(s[i] > '4')
                --cnt;
            tot += cnt * (int)pow(9,len - i -1);
        }
        return tot;
    }
    
    int main()
    {
        char s[10];
        while(cin >> s)
        {
            cout << fun(s) << endl;
        }
        return 0;
    }
    

      

    功不成,身已退
  • 相关阅读:
    React 生命周期
    css 多行文本以...代替
    微信JSSDK配置文件说明
    zepto阻止事件冒泡
    PHP 图片处理PNG颜色丢失
    React 学习笔记(一)
    webpack webpack-dev-server使用指南
    为什么需要使用模块打包工具?
    如何实现微信公户绑定公众号业务
    iOS 手势
  • 原文地址:https://www.cnblogs.com/dongsheng/p/2767986.html
Copyright © 2011-2022 走看看