-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode test.rtf
82 lines (77 loc) · 2.49 KB
/
code test.rtf
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
{\rtf1\ansi\ansicpg936\cocoartf2638
\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\froman\fcharset0 Times-Roman;}
{\colortbl;\red255\green255\blue255;\red0\green0\blue0;}
{\*\expandedcolortbl;;\cssrgb\c0\c0\c0;}
\paperw11900\paperh16840\margl1440\margr1440\vieww28600\viewh15220\viewkind0
\deftab720
\pard\pardeftab720\partightenfactor0
\f0\fs24 \cf0 \expnd0\expndtw0\kerning0
\outl0\strokewidth0 \strokec2 \
\pard\pardeftab720\partightenfactor0
\fs32 \cf0 #Stage 1\
\
\pard\pardeftab720\partightenfactor0
\cf0 \strokec2 import java.util.*;\
import org.apache.commons.lang3.StringUtils;\
public class Main\{\
public static void main(String[] agrs)\{\
Scanner in = new Scanner(System.in);\
String str=in.nextLine();\
String pattern="([a-z])(\\1)\{2,\}";\
Pattern p=Pattern.compile(pattern);\
while(true)\{\
Matcher matcher=p.matcher(str);\
String a="";\
while(matcher.find())\{\
a = matcher.group();\
str = str.replaceAll(a,"");\
System.out.println(str);\
\}\
if(StringUtils.isBlank(a))\{\
break;\
\}\
\} \
\} \
\}
\fs24 \outl0\strokewidth0 \
\pard\pardeftab720\partightenfactor0
\fs32 \cf0 \outl0\strokewidth0 \strokec2 \
\
\pard\pardeftab720\partightenfactor0
\fs24 \cf0 \
\pard\pardeftab720\partightenfactor0
\fs32 \cf0 #Stage 2\
\
import java.util.*;\
import org.apache.commons.lang3.StringUtils;\
public class Main\{\
public static void main(String[] agrs)\{\
Scanner in = new Scanner(System.in);\
String str=in.nextLine();\
String pattern="([a-z])(\\1)\{2,\}";\
Pattern p=Pattern.compile(pattern);\
String wordStr="abcdefghijklmnopqrstuvwxyz\'94;\
while(true)\{\
Matcher matcher=p.matcher(str);\
String a="";\
String b="";\
while(matcher.find())\{\
a = matcher.group();\
int index=wordStr.indexOf(a.charAt(0));\
if(index>0)\{\
b=String.valueOf(wordStr.charAt(index - 1));\
str=str.replaceAll(a,b);\
\}else if(index>-1)\{\
b=String.valueOf(a.charAt(0));\
str=str.replaceAll(a,"");\
\}\
System.out.println(str + ", " + a +" is replaces by "+b);\
\}\
if(StringUtils.isBlank(a))\{\
break;\
\}\
\}\
\} \
\}
\fs24 \
}