HDU4278 Faulty Odometer(進位轉化問題)

來源:互聯網
上載者:User

標籤:hdu4278   進位轉換   c++   faulty odometer   

題目大意:里程錶會錯過0 1 2 3 4 5 6 7 8 9中的 3 和 8 兩個數字 也就是 正常的里程錶顯示0 1 2 3 4 5 6 7 8 9

                    壞掉的里程錶只會顯示 0 1 2 4 5 6 7 9

                                  其實可以看做:0 1 2 3 4 5 6 7  即壞掉的里程錶顯示的是8進位的數字,只需先將顯示的數字換成8進位數,在把8進位數字換位10進位數字就是答案。

#include <iostream>#include <map>#include <sstream>#include <cstring>#include <cstdio>#include <cmath>#include <string>using namespace std;map<char ,char> mp;string str;long long ans;long long trans(long long a){    int y,b=0,i=0;    while(a>=1){      y=a%10;      b+=y*pow(8.0,i);      i++;      a=a/10;    }    return b;}long long fuck(){    string tps;    int len=str.length();    long long tmp,tp;    for(int i=0;i<len;i++){        tps.push_back(mp[str[i]]);    }    stringstream ss(tps);    ss>>tmp;    tp=trans(tmp);    return tp;}int main(){    mp['0']='0';    mp['1']='1';    mp['2']='2';    mp['4']='3';    mp['5']='4';    mp['6']='5';    mp['7']='6';    mp['9']='7';    while(cin>>str){        if(str=="0") return 0;        cout<<str<<": ";        ans=fuck();        cout<<ans<<endl;    }}


 

HDU4278 Faulty Odometer(進位轉化問題)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.