-
Notifications
You must be signed in to change notification settings - Fork 0
/
Check.java
151 lines (147 loc) · 5.07 KB
/
Check.java
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import java.util.StringTokenizer;
import java.io.*;
class Check
{
public static void main(String args[])
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String message = new String();
try{
message = br.readLine();
} catch(IOException e) {
System.out.print("Error");
}
String str = new String();
String b = new String();
str=message;
StringTokenizer tokens = new StringTokenizer(str, " ");
String[] splited = new String[tokens.countTokens()];
int index = 0;
int z=1;
if(str.charAt(str.length()-1) == '4')
{
while(tokens.hasMoreTokens()){
splited[index] = tokens.nextToken();
++index;
}
int j=0;
for(j=0; j<index-1; j++)
{
b=b+splited[j];
b=b+" ";
}
message=b;
}
else
{
str=str.replace("and", "");
str=str.replace("of", "");
str=str.replace("with", "");
str = str.replaceAll("( )+", " ");
StringTokenizer token = new StringTokenizer(str, " ");
while(token.hasMoreTokens()){
splited[index] = token.nextToken();
++index;
}
int j=0;
if(splited[index-1].charAt(0) == '1')
{
for(j=0; j<index-1; j++)
{
if(splited[j].charAt(1) == '+' || splited[j].charAt(1)=='#' || splited[j].charAt(1)=='.')
b=b+splited[j];
else
b=b+splited[j].charAt(0);
}
message=b;
}
if(splited[index-1].charAt(0) == '2')
{
if(index>=4)
{
for(j=0; j<index-1; j++)
{
if(splited[j].charAt(1)=='+' || splited[j].charAt(1)=='#' || splited[j].charAt(1)=='.')
b=b+splited[j];
else{
if(splited[j].length()<1)
b=b+splited[j];
else
b=b+splited[j].charAt(0)+splited[j].charAt(1);
}}
message=b;
}
else if(index==3)
{
for(j=0; j<index-1; j++)
{
if(splited[j].charAt(1) == '+' || splited[j].charAt(1)=='#' || splited[j].charAt(1)=='.')
b=b+splited[j];
else {
if (splited[j].length() <= 2)
b = b + splited[j];
else
b = b + splited[j].charAt(0) + splited[j].charAt(1) + splited[j].charAt(2);
}
}
message=b;
}
else
{
if(splited[0].length()-7<=0)
b=b+splited[0];
else{
for(j=0; j<splited[0].length()-6; j++)
{
b=b+splited[0].charAt(j);
}}
message=b;
}
}
if(splited[index-1].charAt(0) == '3')
{
if(index>=4)
{
for(j=0; j<index-1; j++)
{
if(splited[j].charAt(1)=='+' || splited[j].charAt(1)=='#' || splited[j].charAt(1)=='.')
b=b+splited[j];
else{
if(splited[j].length()<=3)
b=b+splited[j];
else
b=b+splited[j].charAt(0)+splited[j].charAt(1)+splited[j].charAt(2);
}}
message=b;
}
else if(index==3)
{
for(j=0; j<index-1; j++)
{
if(splited[j].charAt(1) == '+' || splited[j].charAt(1)=='#' || splited[j].charAt(1)=='.'){
b=b+splited[j];}
else {
if (splited[j].length() < 4)
b = b+splited[j];
else
b = b + splited[j].charAt(0) + splited[j].charAt(1) + splited[j].charAt(2) + splited[j].charAt(3);
}
}
message=b;
}
else
{
if(splited[0].length()-4<=0)
b=b+splited[0];
else{
for(j=0; j<splited[0].length()-3; j++)
{
b=b+splited[0].charAt(j);
}}
message=b;
}
}
}
System.out.println(message);
}
}