include iostream include string using namespace std int main string an

  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
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include<iostream>
#include <string>
using namespace std;
int main()
{
string s = "", ans="", str;
string ob = "", sub= "", verb = "";
int t = 2;
getline(cin,str);
for(int i=0; i<str.size(); ++i)
{
s = "";
while (str[i] != ' ' && i != str.size())
{
s += str[i];
i++;
}
if(s[s.size() - 1] == ',')
t = 3;
else if(s[s.size() - 1] >= 'a' && s[s.size() - 1] <= 'z')
t = 1;
else
t = 2;
if(s[0] == '(')
{
s[1] = tolower(s[1]);
sub = s.substr(1,s.size()-t);
while(s[s.size()-1] != ')')
{
i++;
s="";
while (str[i] != ' ' && i != str.size())
{
s += str[i];
i++;
}
sub+= " " + s;
}
if(sub[sub.size() -1] == ')')
sub = sub.substr(0, sub.size() - 1);
else if (sub[sub.size() - 2] == ')')
{
sub = sub.substr(0, sub.size() - 2);
t = 3;
}
}
else if(s[0] == '{')
{
s[1] = tolower(s[1]);
ob = s.substr(1,s.size()-t);
while(s[s.size()-1] != '}' && s[s.size()-2] != '}')
{
i++;
s= "";
while (str[i] != ' ' && i != str.size())
{
s += str[i];
i++;
}
ob+= " " + s;
}
if(ob[ob.size() -1] == '}')
ob = ob.substr(0, ob.size() -1);
else if (ob[ob.size() - 2] == '}')
{
ob = ob.substr(0, ob.size() - 2);
t = 3;
}
}
else if(s[0] == '[')
{
s[1] = tolower(s[1]);
verb = s.substr(1,s.size()-t);
while(s[s.size()-1] != ']')
{
s = "";
i++;
while (str[i] != ' ' && i != str.size())
{
s += str[i];
i++;
}
verb+= " " + s;
}
if(verb[verb.size() -1] == ']' )
verb = verb.substr(0, verb.size() -1);
else if (verb[verb.size() - 2] == ']')
{
verb = verb.substr(0, verb.size() - 2);
t = 3;
}
}
else
{
ans += " " + s;
}
if(t == 3)
{
ans+= ob + " " + sub + " " + verb + ',';
}
}
if(ans != "")
ans+= " ";
ans+= ob + " " + sub + " " + verb;
ans[0] = toupper(ans[0]);
cout << ans << endl;
}