POJ - 1025 ~ 1029
1028 - Web Navigation
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Stack<String> back = new Stack<String>();
Stack<String> forward = new Stack<String>();
back.push("http://www.acm.org/");
String str = new String();
while(!(str = in.next()).equals("QUIT")) {
if(str.equals("VISIT")) {
back.push(in.next());
System.out.println(back.peek());
while(!forward.empty()) {
forward.pop();
}
} else if(str.equals("BACK")) {
if(back.size() == 1) {
System.out.println("Ignored");
} else {
forward.push(back.pop());
System.out.println(back.peek());
}
} else {
if(forward.size() == 0) {
System.out.println("Ignored");
} else {
back.push(forward.pop());
System.out.println(back.peek());
}
}
}
in.close();
}
}
1029 - False Coin
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
if(in.hasNext()) {
int n = in.nextInt();
boolean[] trueCoins = new boolean[n + 1];
int[] otherCoins = new int[n + 1];
int test = in.nextInt();
int unEqual = 0;
for(int i = 0; i < test; i++) {
int nums = in.nextInt();
int[] tmp = new int[nums * 2];
for(int j = 0; j < nums * 2; j++) {
tmp[j] = in.nextInt();
}
String s = in.next();
if(s.equals("=")) {
for(int j = 0; j < nums * 2; j++) {
trueCoins[tmp[j]] = true;
}
} else if(s.equals("<")) {
unEqual++;
for(int j = 0; j < nums; j++) {
otherCoins[tmp[j]]--;
}
for(int j = nums; j < nums * 2; j++) {
otherCoins[tmp[j]]++;
}
} else {
unEqual++;
for(int j = 0; j < nums; j++) {
otherCoins[tmp[j]]++;
}
for(int j = nums; j < nums * 2; j++) {
otherCoins[tmp[j]]--;
}
}
}
int count = 0, pos = 0;
for(int i = 1; i <= n; i++) {
if(trueCoins[i]) {
continue;
}
if(otherCoins[i] == unEqual || (0 - otherCoins[i]) == unEqual) {
pos = i;
count++;
if(count != 1) {
break;
}
}
}
if(count == 1) {
System.out.println(pos);
} else {
System.out.println(0);
}
}
in.close();
}
}