class
GFG {
static
boolean
isdigit(
char
c) {
return
c >=
'0'
&& c <=
'9'
;
}
public
static
boolean
issorted(String s)
{
s = s.toLowerCase();
for
(
int
i =
0
; i < s.length() -
1
; i++) {
if
(s.charAt(i) > s.charAt(i +
1
) || isdigit(s.charAt(i))) {
return
false
;
}
}
return
true
;
}
public
static
boolean
issortedre(String s)
{
s = s.toLowerCase();
for
(
int
i =
0
; i < s.length() -
1
; i++) {
if
(s.charAt(i) < s.charAt(i +
1
) || isdigit(s.charAt(i))) {
return
false
;
}
}
return
true
;
}
public
static
void
count(String s) {
String[] ss = s.split(
" "
);
String word;
int
count1 =
0
, count2 =
0
;
for
(
int
i =
0
; i < ss.length; i++) {
word = ss[i];
if
(word.length() ==
1
)
continue
;
if
(issorted(word)) {
count1++;
}
else
if
(issortedre(word)) {
count2++;
}
}
String[] ss1 = s.split(
" "
);
System.out.print(count1 +
" "
);
for
(
int
i =
0
; i < ss1.length; i++) {
word = ss1[i];
if
(word.length() ==
1
)
continue
;
if
(issorted(word)) {
System.out.print(
"\""
+ word +
"\" "
);
}
}
System.out.println();
String[] ss2 = s.split(
" "
);
System.out.print(count2 +
" "
);
for
(
int
i =
0
; i < ss2.length; i++) {
word = ss2[i];
if
(word.length() ==
1
)
continue
;
else
if
(issortedre(word)) {
System.out.print(
"\""
+ word +
"\" "
);
}
}
System.out.println();
}
public
static
void
main(String args[]) {
String s =
"We won the match by 4 runs"
;
count(s);
}
}