Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Scanner;
- public class ccc06j3 {
- public static void main(String[] args) {
- HashMap<Character, String> map = new HashMap<Character, String>();
- // Primitive Reference
- // byte Byte
- // short Short
- // int Integer
- // long Long
- // double Double
- // float Float
- // char Character
- // boolean Boolean
- // key Character
- // value String
- // 'a' "2"
- // 'b' "22"
- // 'c' "222"
- map.put('a',"2");
- map.put('b',"22");
- map.put('c',"222");
- map.put('d',"3");
- map.put('e',"33");
- map.put('f',"333");
- map.put('g',"4");
- map.put('h',"44");
- map.put('i',"444");
- map.put('j',"5");
- map.put('k',"55");
- map.put('l',"555");
- map.put('m',"6");
- map.put('n',"66");
- map.put('o',"666");
- map.put('p',"7");
- map.put('q',"77");
- map.put('r',"777");
- map.put('s',"7777");
- map.put('t',"8");
- map.put('u',"88");
- map.put('v',"888");
- map.put('w',"9");
- map.put('x',"99");
- map.put('y',"999");
- map.put('z',"9999");
- while (true) {
- //input String S
- Scanner sc = new Scanner(System.in);
- String S = sc.next();
- if (S.equals("halt")) {
- break;
- }
- //read char one by one
- char pre = ' ';
- int click = 0;
- for (int i=0; i<S.length(); i++) {
- char C = S.charAt(i); //current char
- String code = map.get(C); //mapping numbers
- click += code.length();
- //has pause
- if (code.charAt(0)==pre) {
- click+=2; //add 2 second pause
- }
- pre = code.charAt(0);
- }
- System.out.println(click);
- }
- //"abca"
- //create temporary variable char pre=' ';
- //first char is a map to "2" "2" first char compare with pre
- //if they are equals, then add 2 second pause
- //pre = "2".charAt(0);
- //second char is b map to "22" "22" first char compare with pre
- //they are equal then add 2 second pause
- //pre = "22".charAt(0)
- //third char is c map to "3" "3" first char compare with pre
- //they are not equals, don't add anything for pause
- //"666"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement