浙大pta 1002 写出这个数 (20 分)c#实现

it2022-05-05  215

1002 写出这个数 (20 分) 读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字。

输入格式: 每个测试输入包含 1 个测试用例,即给出自然数 n 的值。这里保证 n 小于 10 ​100 ​​ 。

输出格式: 在一行内输出 n 的各位数字之和的每一位,拼音数字间有 1 空格,但一行中最后一个拼音数字后没有空格。

输入样例: 1234567890987654321123456789 输出样例: yi san wu

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { string[] word = { "ling", "yi", "er", "san", "si", "wu", "liu", "qi", "ba", "jiu" }; string s = Console.ReadLine(); int count = 0; for(int i = 0; i < s.Length; i++) { count += Convert.ToInt32(s[i].ToString()); } string result=count.ToString(); string real = ""; for(int i = 0; i < result.Length; i++) { if(i== result.Length-1) real += word[Convert.ToInt32(result[i].ToString())]; else real += word[Convert.ToInt32(result[i].ToString())] + " "; } Console.WriteLine(real); //string f = Console.ReadLine(); } } }

最新回复(0)