输入:XXYXYYYXXXXYXYXXXYXYXYXYYXXYXYXYXYYYXXXXXXXXXYXXXXYXYXYXYYYXYYYXYYYXXYYYYYYYYYYXXXYYYXXYXXYYYYXYYXYYYXXXXXYYXYXYXYYYXYXYYXYXYYXXYXXXXYXXYXYYYYYYYYXXXXYYYYYYXYXYYYYXXXXXXXYYYXXYXYXXYYYYXYXYYXXYXYYXYXXYXXYXYXXYXXXYYYXXXYXYYYYYXYXYYXXYYYYXXXYYYYXXXYYYYXXYXYXXYYYXXXYYXXXYYXYYYYXYXXXXYXYXYYYXYYYYXXXXXYXXXXYXYYYYYXXXXYYYXXXXYXYYYYYYXXYYYXXXYXXXYXYXYXYYYXXXYYXXXXXXYYYYXXXYYYYXXXYXXYXXXYYYXXYXYXXXXYYXXYYYYXXXXYXYXXYYYYYXXYYYYYXYYXXXYYYXXXYYYXXXXXYYYXXXYXYYXXXYYYXYYYYXYXYYXYXYYYYXXXYYXXYYYYXXXYYXXYYXXXXXXXXYXYYYXYYYYYXYYXXYYXXYXXXXYXXXXYXXXYXYXYXXXXXXXYYXXX
代码1:
public class Test {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.nextLine();
Integer countX = 0;
Integer countY = 0;
Integer count = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'X') {
countX++;
} else {
countY++;
}
if (countX == countY) {
//判断为均衡字符串
System.out.println(countX + " " + countY);
System.out.print("\n");
count++;
}
}
System.out.println(count);
}
}
运行结果:
XXYXYYYXXXXYXYXXXYXYXYXYYXXYXYXYXYYYXXXXXXXXXYXXXXYXYXYXYYYXYYYXYYYXXYYYYYYYYYYXXXYYYXXYXXYYYYXYYXYYYXXXXXYYXYXYXYYYXYXYYXYXYYXXYXXXXYXXYXYYYYYYYYXXXXYYYYYYXYXYYYYXXXXXXXYYYXXYXYXXYYYYXYXYYXXYXYYXYXXYXXYXYXXYXXXYYYXXXYXYYYYYXYXYYXXYYYYXXXYYYYXXXYYYYXXYXYXXYYYXXXYYXXXYYXYYYYXYXXXXYXYXYYYXYYYYXXXXXYXXXXYXYYYYYXXXXYYYXXXXYXYYYYYYXXYYYXXXYXXXYXYXYXYYYXXXYYXXXXXXYYYYXXXYYYYXXXYXXYXXXYYYXXYXYXXXXYYXXYYYYXXXXYXYXXYYYYYXXYYYYYXYYXXXYYYXXXYYYXXXXXYYYXXXYXYYXXXYYYXYYYYXYXYYXYXYYYYXXXYYXXYYYYXXXYYXXYYXXXXXXXXYXYYYXYYYYYXYYXXYYXXYXXXXYXXXXYXXXYXYXYXXXXXXXYYXXX
3 3
4 4
39 39
40 40
42 42
43 43
44 44
46 46
53 53
68 68
69 69
11
代码2:
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.nextLine();
int countX = 0;
int countY = 0;
int count = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'X') {
countX++;
} else {
countY++;
}
if (countX == countY) {
//判断为均衡字符串
System.out.println(countX + " " + countY);
System.out.print("\n");
count++;
}
}
System.out.println(count);
}
运行结果:
XXYXYYYXXXXYXYXXXYXYXYXYYXXYXYXYXYYYXXXXXXXXXYXXXXYXYXYXYYYXYYYXYYYXXYYYYYYYYYYXXXYYYXXYXXYYYYXYYXYYYXXXXXYYXYXYXYYYXYXYYXYXYYXXYXXXXYXXYXYYYYYYYYXXXXYYYYYYXYXYYYYXXXXXXXYYYXXYXYXXYYYYXYXYYXXYXYYXYXXYXXYXYXXYXXXYYYXXXYXYYYYYXYXYYXXYYYYXXXYYYYXXXYYYYXXYXYXXYYYXXXYYXXXYYXYYYYXYXXXXYXYXYYYXYYYYXXXXXYXXXXYXYYYYYXXXXYYYXXXXYXYYYYYYXXYYYXXXYXXXYXYXYXYYYXXXYYXXXXXXYYYYXXXYYYYXXXYXXYXXXYYYXXYXYXXXXYYXXYYYYXXXXYXYXXYYYYYXXYYYYYXYYXXXYYYXXXYYYXXXXXYYYXXXYXYYXXXYYYXYYYYXYXYYXYXYYYYXXXYYXXYYYYXXXYYXXYYXXXXXXXXYXYYYXYYYYYXYYXXYYXXYXXXXYXXXXYXXXYXYXYXXXXXXXYYXXX
3 3
4 4
39 39
40 40
42 42
43 43
44 44
46 46
53 53
68 68
69 69
277 277
12