//2019.9.19 科达笔试题:输入一串字符,删除所有大写字母
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define MAX 1024
int main()
{
cout << "请输入一串英文:";
char str[MAX];
cin >> str;
int i = 0, j = 0;
while (str[i]) { /*这里用s[i]当条件,而不用字符串的长度
是因为\0也会被移动, 因此长度也会发生改变*/
if (str[i] >= 'A' && str[i] <= 'Z') //为大写字母时
{
//将s[i]后面所有的字符向前移
j = i;
while (str[j] = str[j + 1])
++j;
//这里i不自增的原因是:若有两个大写字母挨着,便会跨过一个
}
else ++i;
}
puts(str);
return 0;
}
输入一个字符串,删除所有大写字母
最新推荐文章于 2023-12-10 14:14:57 发布