#include <bits/stdc++.h>
using
namespace
std;
bool
ischar(
char
x)
{
if
((x >=
'A'
&& x <=
'Z'
)
|| (x >=
'a'
&& x <=
'z'
)) {
return
1;
}
return
0;
}
bool
isnum(
char
x)
{
if
(x >=
'0'
&& x <=
'9'
)
return
1;
return
0;
}
void
findIdandDomain(string S,
int
N)
{
string ID, Domain;
vector<string> words;
string curr =
""
;
for
(
int
i = 0; i < N; i++) {
if
(S[i] ==
' '
) {
words.push_back(curr);
curr =
""
;
}
else
{
if
(S[i] ==
'.'
) {
if
(i + 1 == N
|| (i + 1 < N
&& S[i + 1] ==
' '
))
continue
;
}
curr += S[i];
}
}
if
(curr.length())
words.push_back(curr);
for
(string ss : words) {
if
(ss.size() == 10) {
bool
flag = 0;
for
(
int
j = 0; j <= 9; j++) {
if
(j >= 5 && j < 9) {
if
(isnum(ss[j]) == 0)
flag = 1;
}
else
{
if
(ischar(ss[j]) == 0)
flag = 1;
}
}
if
(!flag) {
ID = ss;
}
}
if
(ss.substr(0, 3) ==
"www"
&& ss.substr(
ss.length() - 3, 3)
==
"com"
) {
Domain = ss.substr(
4, ss.size() - 4);
}
}
cout <<
"ID = "
<< ID
<< endl;
cout <<
"Domain = "
<< Domain;
}
int
main()
{
string S =
"We thank ABCDE1234F for visiting "
"us and buying "
"products item AMZrr@!k. For more "
"offers, visit "
"us at www.amazon.com"
;
int
N = S.length();
findIdandDomain(S, N);
return
0;
}
Original page link
Best Cool Tech Gadgets
Top favorite technology gadgets
0 comments:
Post a Comment