-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsysAdminBoB.cpp
More file actions
88 lines (85 loc) · 1.9 KB
/
sysAdminBoB.cpp
File metadata and controls
88 lines (85 loc) · 1.9 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters.
Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string,
where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once.
Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators,
and there is impossible to determine, where the boundaries between addresses are.
Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that.*/
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int check = 0;
vector<char> v;
string s;
cin >> s;
if (s[0] == '@')
{
cout << "No solution";
return 0;
}
if (s[s.length() - 1] == '@')
{
cout << "No solution";
return 0;
}
for (int i = 0; i < s.length()-1; i++)
{
if (s[i] == '@' && s[i + 1] == '@')
{
cout << "No solution";
return 0;
}
}
for (int i = 0; i < s.length(); i++)
{
check = 0;
if (s[i] == '@')
{
cout << "No solution\n";
return 0;
}
while (s[i] != '@' && i < s.length())
{
v.push_back(s[i]);
i++;
}
if (i == s.length())
{
cout << "No solution\n";
return 0;
}
if (s[i] == '@')
{
v.push_back(s[i]);
v.push_back(s[i + 1]);
i++;
}
for (int j = i; j < s.length(); j++)
{
if (s[j] == '@')
check = 1;
}
if (check == 1)
{
v.push_back(',');
continue;
}
if (check == 0)
{
i++;
while (i < s.length())
{
v.push_back(s[i]);
i++;
}
v.push_back(',');
break;
}
}
int size = 0;
size = v.size() - 1;
for (int i = 0; i < size; i++)
cout << v[i];
return 0;
}