C語言實驗——大小寫轉換
阿新 • • 發佈:2019-01-27
Problem Description
把一個字串裡所有的大寫字母換成小寫字母,小寫字母換成大寫字母。其他字元保持不變。
Input
輸入為一行字串,其中不含空格。長度不超過80個字元。
Output
輸出轉換好的字串。
Sample Input
ABCD123efgh
Sample Output
abcd123EFGH
Hint
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace test1 { class Program { static void Main(string[] args) { string s; s = Console.ReadLine(); char[] a = s.ToCharArray(); int i; for(i=0;i<s.Length;i++) { if(a[i]>='a'&&a[i]<='z') { a[i] = (char)(a[i] - 32); } else if(a[i]>='A'&&a[i]<='Z') { a[i] = (char)(a[i] + 32); } } Console.WriteLine(a); } } }