2193 - P564 4
P564 更改为从键盘读入邮件的信息(不用从文件中读取)。
Input
n// 邮件的数量
n个邮件地址
Output
输出经过清洗后的邮件地址
Examples
Input
5 123@ecnu.cn 124ecnu.cn 122@ecnu.cn 125@ecnu.cn 122@ecnu.cn
Output
123@ecnu.cn 122@ecnu.cn 125@ecnu.cn
Solution C++
#include <string> #include <iostream> using namespace std; int Get(string, char); int main() { int n, i, j, index; bool exist, proper; string s[100], temp; cin >> n; for (i = index = 0; i < n; i++) { exist = false; proper = false; cin >> temp; for (j = 0; j < index; j++) { if (s[j] == temp) { exist = true; break; } } if (!exist) { if (Get(temp, '@') == 1 && Get(temp, '.') == 1 && temp.find('@') < temp.find('.')) proper = true; } if (!exist && proper) { s[index] = temp; index++; } } for (i = 0; i < index; i++) cout << s[i] << endl; return 0; } int Get(string s, char a) { int sum = 0, i = 0, l = s.size(); for (; i < l; i++) { if (s[i] == a) sum++; } return sum; }