在现在的各种互联网应用中,在一段文字中使用'@'字符来提起一名用户是流行的做法。
例如:
"@littleho submitted his code 30 times before he got passed the system test."
其中littleho就是一个用户名。我们规定在一段文字中,'@'字符之后一段连续的、非空的大小写英文字母组成的字符串被视为提起的用户名。
给定一段文字,请你输出其中所有提到的用户名。
Input一行文本,只包含大小写字母、标点符号和空格。长度不超过800。
Output按文本中的顺序输出所有提到的用户名,之间用一个空格隔开。重复提到的相同用户名也重复输出。
@abc:@@,@littleho's code is so confusing. @abc.Sample Output
abc littleho abc
题目本身没有太大难度,记录是因为输出的方式需要特别注意,不能有多余的空格出现
#include <bits/stdc++.h>
using namespace std;
const int inf = 810;
char th[inf];
int main()
{
gets(th);
int len = strlen(th);
int N = 0;
int fou = false;
for(int i = 0; i < len;){
if(th[i] == '@'){
while(i < len){
i ++;
if(th[i] >= 'a' && th[i] <= 'z' || (th[i] >= 'A' && th[i] <= 'Z')){
if(fou && N == 1) cout << ' ';
cout << th[i];
N += 2;
fou = true;
}else {
N = 1;
break;
}
}
}else i ++;
}
cout <<endl;
return 0;
}