Description
Sequential detector is a very important device in Hardware experiments. But is very difficult for many students such as HeroWei. In nearest days, his teacher Miss Fang let him simulate sequence detector. But there many sequence here ,and Miss Fang add the difficulty that when she give HeroWei a sequence and a string ,you must tell her how many string here in this sequence. But now Miss Fang simplified the problem for HeroWei, she just give Herowei a sequence and let HeroWei play a game with it.
When comes a character , it must compare with the rightmost one of sequence, if it’s the same with the coming characters ,the coming one just join the string. Most the right side. Otherwise all the characters in the sequence must change its value, 0 to 1 and 1 to 0,then the coming one add to its right side. Here is an example, if there is a sequence ‘110’ when comes a character 0,the sequence become ‘1100’ at last, if comes a character 1,the sequence become ‘0011’ at last.
It’s very difficult for HeroWei to play the game. Can you help him?
Input
Each line contains a composed by a string of 0s and 1s.the input is ended by EOF.
Output
For each given sequence you just play with this string as descripted above.Output a line contains two integers ,which are the number of 0s and 1s in the sequence after the game.
Sample Input
0
000
110
1111
1010
010100
Sample Output
1 0
3 0
0 4
4 0
分析?
又是水题,,,直接看最后一位即可。
代码?
/**
* Time 254ms
* @author wowpH
* @version 1.1
* @date 2019年6月29日下午12:07:38
* Environment: Windows 10
* IDE Version: Eclipse 2019-3
* JDK Version: JDK1.8.0_112
*/
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
String s = sc.next();
if (s.endsWith("0")) {
System.out.println(s.length() + " " + 0);
} else {
System.out.println(0 + " " + s.length());
}
}
sc.close();
}
}