Result: Accepted
Time: 4ms
Memory: 1756kB
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
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define INF 0x3f3f3f3f
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 10;
int main()
{
int n;
scanf("%d",&n);
getchar();
while(n--)
{
string a;
getline(cin,a);
int flag = 0;
for(int i=0;i<a.size();i++)
{
if(flag == 0 && a[i] == 't' && a[i - 1] =='n' && a[i - 2] == 'i' && a[i - 3] == 'r' && a[i - 4] == 'p' && a[i+1] == ' ')
{
flag = 1;
printf("%c",a[i]);
printf("(");
}
else if(flag == 1 && a[i] == ' ')
{
flag = 2;
continue;
}
else
printf("%c",a[i]);
}
if(flag > 0)
puts(")");
else
printf("\n");
}
}