Created
July 16, 2011 02:43
-
-
Save wingyplus/1085933 to your computer and use it in GitHub Desktop.
Gweans2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Main; | |
import java.util.ArrayList; | |
import java.util.Scanner; | |
public class Doublets { | |
public static void main(String[] args) { | |
Scanner s = new Scanner(System.in); | |
ArrayList<String> l = new ArrayList<String>(); | |
boolean b = false; | |
while(s.hasNextLine()) { | |
if (b) { | |
String[] se = s.nextLine().split(" "); // start to end. | |
if (se[0].length() != se[1].length()) { | |
System.out.println("No solution."); | |
} else { | |
String start = se[0]; // set start point. | |
int solution = check(se[0], se[1]); | |
String[] stack = new String[solution]; | |
for (int j = l.indexOf(se[0]); j < l.size(); j++) { | |
String seq = l.get(j); | |
int count = 0; | |
String buf = se[0]; | |
if (start.length() != seq.length()) { // length of seq is equal se[0] | |
continue; | |
} else if (se[1].equals(seq)) { // is end word | |
System.out.println(seq); | |
break; | |
} else { | |
count = check(start, seq); | |
if (count == 0 || count == 1) { | |
System.out.println(seq); | |
start = seq; | |
} | |
} | |
} | |
} | |
} else { | |
String line = s.nextLine(); | |
if (line.equals("")) { | |
b = true; | |
continue; | |
} else { | |
l.add(line); | |
} | |
} | |
} | |
} | |
private static int check(String s, String s2) { | |
int count = 0; | |
for (int i = 0; i < s.length(); i++) { | |
if (s.charAt(i) != s2.charAt(i)) count++; | |
} | |
return count; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Main; | |
import java.util.HashMap; | |
import java.util.Scanner; | |
public class FatMouse { | |
public static void main(String[] args) { | |
Scanner s = new Scanner(System.in); | |
HashMap <String, String> m = new HashMap<String, String>(); | |
boolean b = false; | |
while(s.hasNextLine()) { | |
if (b) { | |
String key = s.next(); | |
if (m.containsKey(key)) System.out.println(m.get(key)); | |
else System.out.println("eh"); | |
} else { | |
String line = s.nextLine(); | |
if (line.equals("")) { | |
b = true; | |
continue; | |
} else { | |
String[] kv = line.split(" "); | |
m.put(kv[1], kv[0]); | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Main; | |
import java.util.Scanner; | |
public class gweans { | |
public static void main(String[] args) { | |
Scanner s = new Scanner(System.in); | |
while(s.hasNext()) { | |
int input1 = s.nextInt(); | |
String operand = s.next(); | |
int input2 = s.nextInt(); | |
if (operand.equals(">")) System.out.println("case 1:" + (input1 > input2)); | |
else if (operand.equals(">=")) System.out.println("case 1:" + (input1 >= input2)); | |
else if (operand.equals("<")) System.out.println("case 1:" + (input1 < input2)); | |
else if (operand.equals("<=")) System.out.println("case 1:" + (input1 <= input2)); | |
else if (operand.equals("==")) System.out.println("case 1:" + (input1 == input2)); | |
else if (operand.equals("!=")) System.out.println("case 1:" + (input1 != input2)); | |
else if (operand.equals("E")) break; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Main; | |
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.util.Scanner; | |
public class pink { | |
public static void main(String[] args) { | |
File file = new File("Testcase/pink.in"); | |
try { | |
Scanner s = new Scanner (file); | |
while (s.hasNextLine()) { | |
String str = s.nextLine().replaceAll("dd", "p").replaceAll("[^a-z&&[\\S\\d]]", "").replaceAll("pink", "floyd").replaceAll("([^c])ei", "$1ie"); | |
System.out.println(str); | |
} | |
} catch (FileNotFoundException e) { | |
// TODO Auto-generated catch block | |
e.printStackTrace(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Main; | |
import java.util.HashMap; | |
import java.util.HashSet; | |
import java.util.Map; | |
import java.util.Scanner; | |
import java.util.Set; | |
public class SampleMap { | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
Map <Character,Integer> m = new HashMap<Character, Integer>(); | |
Set<String> s = new HashSet<String>(); | |
m.put('a', 2); | |
m.put('b', 2); | |
m.put('c', 2); | |
m.put('d', 3); | |
m.put('e', 3); | |
m.put('f', 3); | |
m.put('g', 4); | |
m.put('h', 4); | |
m.put('i', 4); | |
m.put('j', 5); | |
m.put('k', 5); | |
m.put('l', 5); | |
m.put('m', 6); | |
m.put('n', 6); | |
m.put('o', 6); | |
m.put('p', 7); | |
m.put('q', 7); | |
m.put('r', 7); | |
m.put('s', 7); | |
m.put('t', 8); | |
m.put('u', 8); | |
m.put('v', 8); | |
m.put('w', 9); | |
m.put('x', 9); | |
m.put('y', 9); | |
m.put('z', 9); | |
Scanner scan = new Scanner(System.in); | |
int n = scan.nextInt(); | |
for(int i = 0; i < n; i++) { | |
int mm = scan.nextInt(); | |
s.clear(); | |
for (int j = 0; j < mm; j++) { | |
String ss = scan.next(); | |
StringBuffer sss = new StringBuffer(); | |
for (int l = 0; l < ss.length(); l++) { | |
sss.append(m.get(ss.charAt(l))); | |
} | |
s.add(sss.toString()); | |
} | |
System.out.println(s.size()); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Main; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Scanner; | |
public class WordSorting { | |
public static void main(String[] args) { | |
Scanner s = new Scanner(System.in); | |
HashMap <Integer, ArrayList<String>> m = new HashMap<Integer, ArrayList<String>>(); | |
while (true) { | |
String in = s.nextLine(); | |
if (in.equals("0")) break; // exit program | |
int sum = 0; | |
for (int i = 0; i < in.length(); i++) { | |
sum += in.charAt(i) - 'a' + 1; | |
} | |
if (!m.containsKey(sum)) // not contain key | |
m.put(sum, new ArrayList<String>()); | |
m.get(sum).add(in); | |
} | |
List<Integer> sort = new ArrayList<Integer>(m.keySet()); | |
Collections.sort(sort); | |
for (Integer key : sort) { | |
for (String val : m.get(key)) | |
System.out.println(val); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bugs
doublets.java
booster
rooster
rfoster
roaster
coasted
roasted
coastal
postal
TEST FAIL