-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy path21A. Jabber ID.cpp
93 lines (69 loc) · 1.78 KB
/
21A. Jabber ID.cpp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include <string>
using namespace std;
bool isTrue(string s) {
string tmp = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ1234567890_";
for (int i = 0; i < s.length(); i++) {
if (tmp.find(s[i]) == string::npos) {
return false;
}
}
return true;
}
bool isTrueH(string s) {
string tmp = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ1234567890_.";
for (int i = 0; i < s.length(); i++) {
if (tmp.find(s[i]) == string::npos) {
return false;
}
}
return true;
}
bool doubleDot(string s) {
for (int i = 0; i < s.length(); i++) {
if (s[i] == '.' && s[i + 1] == '.') {
return false;
}
}
return true;
}
int main() {
string s, username, hostname, resource, tmp;
getline(cin, s);
username = s.substr(0, s.find('@'));
if (username.length() > 16 || !isTrue(username) || username.empty()) {
cout << "NO" << endl;
return 0;
}
hostname = s.substr(s.find('@') + 1, s.find('/') - s.find('@') - 1);
if (hostname.length() > 32 || !doubleDot(hostname) || !isTrueH(hostname) || hostname.empty() || hostname[0] == '.') {
cout << "NO" << endl;
return 0;
}
while (hostname.length() > 0) {
tmp = hostname.substr(0, hostname.find('.'));
if (hostname.find('.') == string::npos)
hostname.clear();
else {
hostname.erase(0, hostname.find('.'));
if (hostname == ".") {
cout << "NO" << endl;
return 0;
}
hostname.erase(0, 1);
}
if (tmp.length() > 16) {
cout << "NO" << endl;
return 0;
}
}
if (s.find('/') != string::npos) {
resource = s.substr(s.find('/') + 1);
if (resource.length() > 16 || !isTrue(resource) || resource.empty()) {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}