PAT Basic 1002
生活随笔
收集整理的這篇文章主要介紹了
PAT Basic 1002
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1002?寫出這個數?(20 分)
注意輸出順序即可
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <vector>
#include<algorithm>
#include<string>
#define debug 0
using namespace std;
int main() {
#if debug
?? ?freopen("in.txt", "r", stdin);
#endif
?? ?
?? ?char a[102];
?? ?cin >> a;
?? ?string B[10] = { "ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
?? ?int s = 0;
?? ?for (int i = 0; a[i] != '\0'; i++)
?? ?{
?? ??? ?s = s + a[i] - '0';
?? ?}
?? ?int c = 0;
?? ?string A[4];
?? ?int count = 0;
?? ?while (s >= 10)
?? ?{
?? ??? ?c = s % 10;
?? ??? ?//cout << B[c]<<' ';
?? ??? ?A[count++] = B[c];
?? ??? ?s /= 10;
?? ?}
?? ?cout << B[s];
?? ?for (int i = count-1; i>=0; i--)
?? ?{
?? ??? ?cout << ' ' << A[i];
?? ?}
#if debug
?? ?freopen("CON", "r", stdin);
#endif
?? ?return 0;
}
讀入一個正整數?n,計算其各位數字之和,用漢語拼音寫出和的每一位數字。
輸入格式:
每個測試輸入包含 1 個測試用例,即給出自然數?n?的值。這里保證?n?小于?10?100??。
輸出格式:
在一行內輸出?n?的各位數字之和的每一位,拼音數字間有 1 空格,但一行中最后一個拼音數字后沒有空格。
輸入樣例:
1234567890987654321123456789輸出樣例:
yi san wu注意輸出順序即可
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include <vector>
#include<algorithm>
#include<string>
#define debug 0
using namespace std;
int main() {
#if debug
?? ?freopen("in.txt", "r", stdin);
#endif
?? ?
?? ?char a[102];
?? ?cin >> a;
?? ?string B[10] = { "ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
?? ?int s = 0;
?? ?for (int i = 0; a[i] != '\0'; i++)
?? ?{
?? ??? ?s = s + a[i] - '0';
?? ?}
?? ?int c = 0;
?? ?string A[4];
?? ?int count = 0;
?? ?while (s >= 10)
?? ?{
?? ??? ?c = s % 10;
?? ??? ?//cout << B[c]<<' ';
?? ??? ?A[count++] = B[c];
?? ??? ?s /= 10;
?? ?}
?? ?cout << B[s];
?? ?for (int i = count-1; i>=0; i--)
?? ?{
?? ??? ?cout << ' ' << A[i];
?? ?}
#if debug
?? ?freopen("CON", "r", stdin);
#endif
?? ?return 0;
}
轉載于:https://www.cnblogs.com/lxzbky/p/10497820.html
總結
以上是生活随笔為你收集整理的PAT Basic 1002的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一分钟学会登录所有路由器管理界面 如何登
- 下一篇: 数据操作