forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path274.cpp
More file actions
66 lines (56 loc) · 1.37 KB
/
274.cpp
File metadata and controls
66 lines (56 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//ac
#include <iostream>
#include <string>
using namespace std;
string letter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
string symbol = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-";
bool IsWord(string str) {
if (str.size() == 0) return false;
for (int i = 0; i < str.size(); ++i) {
int pos = symbol.find_first_of(str[i]);
if (pos == -1) return false;
}
return true;
}
bool IsDomain(string str) {
if (str.size() < 2 || str.size() > 3) return false;
for (int i = 0; i < str.size(); ++i) {
int pos = letter.find_first_of(str[i]);
if (pos == -1) return false;
}
return true;
}
bool IsPrefix(string str) {
int pos = str.find_last_of('.');
if (pos == -1) {
return IsWord(str);
} else {
return IsPrefix(str.substr(0, pos)) && IsWord(str.substr(pos + 1));
}
}
bool IsSuffix(string str) {
int pos = str.find_last_of('.');
if (pos == -1) return false;
return IsPrefix(str.substr(0, pos)) && IsDomain(str.substr(pos + 1));
}
bool IsAddress(string str) {
int pos = str.find_first_of('@');
if (pos == -1) return false;
return IsPrefix(str.substr(0, pos)) && IsSuffix(str.substr(pos + 1));
}
char s[200];
void run() {
cin.getline(s, 200, '\n');
string str(s);
if (IsAddress(str)) cout << "YES" << endl;
else cout << "NO" << endl;
}
int main() {
int n;
cin >> n;
cin.getline(s, 200, '\n');
while (n--) {
run();
}
return 0;
}