C语言实验——大小写转换

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);
         
        }
    }
}

猜你喜欢

转载自blog.csdn.net/feissss/article/details/82856099
今日推荐