PAT 1005. Spell It Right (20)
7051 단어 right
너무 물 에 젖다
1 #include<cstdio>
2 #include<iostream>
3 #include<sstream>
4
5 using namespace std;
6
7 const char *english[] = {
8 "zero",
9 "one",
10 "two",
11 "three",
12 "four",
13 "five",
14 "six",
15 "seven",
16 "eight",
17 "nine",
18 "ten"
19 };
20
21 const int MAXN = 200;
22 char num[MAXN];
23
24 int add(char *s) {
25 int result = 0;
26 while(*s) {
27 result += *s - '0';
28 ++s;
29 }
30 return result;
31 }
32
33 void print(int n) {
34 stringstream ss;
35 ss << n;
36 string str = ss.str();
37 cout << english[str[0] - '0'];
38 for (int i = 1; i < str.size(); ++i) {
39 cout << " " << english[str[i] - '0'];
40 }
41 cout << endl;
42 }
43 int main() {
44 while(cin >> num) {
45 print(add(num));
46 }
47 return 0;
48 }
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Populating Next Right Pointers in Each Node I or IIFollow up for problem "Populating Next Right Pointers in Each Node". What if the given tree could be any binary tree? Wo...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.