using System; // Written by Sheauhaw Jang // 2020-09-22 10:50:57 namespaceCSharp_Week1_A { publicclassCalculate { publicstaticintGet(int a, int b, int type) { switch(type) { case0: return a + b; case1: return a - b; case2: return a * b; case3: return a / b; } return0; } } classProgram { staticvoidMain(string[] args) { int a = Convert.ToInt32(Console.ReadLine()); int b = Convert.ToInt32(Console.ReadLine()); for (int i = 0; i < 4; ++i) { if (i > 0) Console.Write(' '); Console.Write(Calculate.Get(a, b, i)); } } } }
using System; // Written by Sheauhaw Jang // 2020-09-22 11:44:47 namespaceCSharp_Week1_C { publicclassEncode { staticintAddModulo(int x, int p) { return x >= p ? x - p : x; } staticvoid Swap<T>(ref T a, ref T b) { T tmp = b; b = a; a = tmp; } publicstaticint[] DoEncoding(string x) { int[] code = newint[x.Length]; for (int i = 0; i < x.Length; ++i) { code[i] = x[i] - '0'; code[i] = AddModulo(code[i] + 7, 10); } Swap(ref code[0], ref code[2]); Swap(ref code[1], ref code[3]); return code; } publicstaticvoidWriteCode(string x) { int[] code = DoEncoding(x); foreach (int digit in code) Console.Write(digit); } } classProgram { staticvoidMain(string[] args) { string x = Console.ReadLine(); Encode.WriteCode(x); } } }
D. 字符串输入输出
输入一个字符串,按照样例格式输出。
样例:
Alice
Hi Alice,
Welcome to C# 2020!
Best wishes!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
using System; // Written by Sheauhaw Jang // 2020-09-22 11:58:50 namespaceCSharp_Week1_D { classProgram { staticvoidMain(string[] args) { string s = Console.ReadLine(); Console.WriteLine("Hi {0},", s); Console.WriteLine("Welcome to C# 2020!"); Console.WriteLine(); Console.WriteLine("Best wishes!"); } } }
E. 字符大小写转换
输入一个字母,如果它是小写字母则输出它的大写字母,如果它是大写字母输出它的小写字母。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
using System; // Written by Sheauhaw Jang // 2020-09-22 21:28:37 namespaceCSharp_Week1_E { classProgram { staticvoidMain(string[] args) { int s = Console.Read(); if (s >= 'a' && s <= 'z') s = s - 'a' + 'A'; else s = s - 'A' + 'a'; Console.WriteLine(Convert.ToChar(s)); } } }