标签:msu specific english chart nta line using cin its
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.
Each input file contains one test case. Each case occupies one line which contains an N (≤10?100??).
For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.
12345
one five
#include<stdio.h> #include<iostream> #include<string> using namespace std; int charToInt(char n) { int result; switch(n) { case ‘0‘: result = 0; break; case ‘1‘: result = 1; break; case ‘2‘: result = 2; break; case ‘3‘: result = 3; break; case ‘4‘: result = 4; break; case ‘5‘: result = 5; break; case ‘6‘: result = 6; break; case ‘7‘: result = 7; break; case ‘8‘: result = 8; break; case ‘9‘: result = 9; break; default: break; } return result; } string intToString(int n) { string result; switch(n) { case 0: result = "zero"; break; case 1: result = "one"; break; case 2: result = "two"; break; case 3: result = "three"; break; case 4: result = "four"; break; case 5: result = "five"; break; case 6: result = "six"; break; case 7: result = "seven"; break; case 8: result = "eight"; break; case 9: result = "nine"; break; default: break; } return result; } int main() { char N; int sum = 0; while(cin >> N) { sum += charToInt(N); } if(sum == 0) { cout << "zero" <<endl; return 0; } int num[101]; //sum存入num中 int p = 0;//记录sum的位数 while(sum != 0) { num[p] = sum%10; sum = sum/10; p++; } for(int i = p-1;i > 0;i--) { cout << intToString(num[i]) << " "; } cout << intToString(num[0]) << endl; return 0; }
标签:msu specific english chart nta line using cin its
原文地址:https://www.cnblogs.com/meiqin970126/p/9563327.html