zoj 1334 Basically Speaking

來源:互聯網
上載者:User
#include "iostream"#include "map"#include "string"#include "cmath"#include "algorithm"#include "iomanip"using namespace std;int main(){string str, ans;int b1, b2, i, j, len1, len2, num;map<char, int> m;//下面的映射由字母轉換為數字!m['0'] = 0, m['1'] = 1, m['2'] = 2, m['3'] = 3, m['4'] = 4, m['5'] = 5, m['6'] = 6, m['7'] = 7, m['8'] = 8, m['9'] = 9,m['A'] = 10, m['B'] = 11, m['C'] = 12, m['D'] = 13, m['E'] = 14, m['F'] = 15;while (cin >> str >> b1 >> b2){num = 0;ans = "";len1 = str.length();for (i = len1-1, j = 0; i >= 0; i--, j++)num += m[str[i]] * pow(b1, double(j));while (num){int temp;temp = num % b2;if (temp >= 10)//由數字轉換為字母!{switch(temp){case 10: ans += 'A';break;case 11:ans += 'B';break;case 12:ans += 'C';break;case 13:ans += 'D';break;case 14:ans += 'E';break;case 15:ans += 'F';break;}}else     ans += num % b2 + 48;num /= b2;}len2 = ans.length();if (len2 > 7)cout << "  ERROR" << endl;else{reverse(ans.begin(), ans.end());cout <<setiosflags(ios::right); //c++輸出控制!cout << setw(7) << ans << endl;}}}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.