1874 - C语言考试练习题_保留字母

编一个程序,输入一个字符串,将组成字符串的所有非英文字母的字符删除后输出。

题目输入

一个字符串,长度不超过80个字符

题目输出

删掉非英文字母后的字符串。

输入/输出样例

题目输入

abc123+xyz.5

题目输出

abcxyz

C++解答

#include<iostream>
#include<string>
#include<cctype>
using namespace std;
int main()
{
	string from,to;
	getline(cin,from);
	int len=from.size(),j=0;
	for (int i=0; i<len; i++)
		if (isalpha(from[i])) to+=from[i];
	cout<<to<<endl;
	return 0;
}
时间限制 1 秒
内存限制 128 MB
讨论 统计
上一题 下一题