您的位置:首页 > 编程语言 > C语言/C++

【C语言训练】大、小写问题

2018-02-09 11:24 211 查看
题目链接:http://115.28.203.224/problem.php?cid=1010&pid=5

题目描述

输入一串字符,将其中的大写变成小写,若不为大写则原样输出

输入

任意字符串(长度在100以内)以回车表示输入结束

输出

将其中的大写 输出相应的小写,若不为大写则原样输出

样例输入

A123b

样例输出

a123b

代码

1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #define maxlen 1100
5 using namespace std;
6 char str[maxlen];
7 int main()
8 {
9     while (gets(str))
10     {
11         int len = strlen(str);
12         for (int i = 0; i < len; ++i)
13         {
14             if (str[i] >= 'A' && str[i] <= 'Z')
15                 printf("%c", str[i] - 'A' + 'a');
16             else
17                 printf("%c", str[i]);
18         }
19         cout<<endl;
20     }
21     return 0;
22 }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: