Re: confuse 489 with online judge
Posted: Thu Oct 09, 2008 12:30 pm
What is the output for input
1
cheese
ch
1
cheese
ch
Code: Select all
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Main {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String s1 = in.readLine();
while (!s1.equals("-1") ) {
int roundNo = Integer.parseInt(s1);
String palavra = in.readLine();
int[] word = new int[26];
int counterSucess = 0;
for (int i = 0; i < palavra.length(); i++) {
word[palavra.charAt(i)-97]++;
counterSucess++;
}
String advinhacao = in.readLine();
int counterError = 0;
boolean[] letters = new boolean[26];
for (int i = 0; i < advinhacao.length(); i++) {
Character c = advinhacao.charAt(i);
int indice = c-97;
if (!letters[indice]) {
if (word[indice]!=0) {
counterSucess -= word[indice];
word[indice] = 0;
letters[indice]= true;
} else {
counterError++;
letters[indice]= true;
}
}
if (counterError == 7) break;
if (counterSucess==0) break;
}
System.out.println("Round " + roundNo);
if (counterError == 7)
System.out.println("You lose.");
else if (counterSucess == 0)
System.out.println("You win.");
else System.out.println("You chickened out.");
s1 = in.readLine();
}
}
}
Code: Select all
1
cheese
chese
2
cheese
abcdefg
3
cheese
abcdefgij
4
rommel
romlnptuyq
5
rommel
romlnptuyqw
6
casa
ca
7
otorrinolaringologia
otr
8
peru
abcdefghijklmno
9
lastima
la
10
aaaaaaaaaaaaaaaaaaaaaa
a
11
bobobobobobobo
b
12
lalalalabababababaaaaa
alhhhhhhhhhhhhhhhhhhhhhhh
13
lkjaskljfkjklsalsdjfslkjfjf
dfklsdfskld
14
nbmbmmbnbbmbmbmbmnbnbnbmbmmbbnbnnbmbmbmboffiifififififfiif
ppppppppppppppppppppppppppppppppppwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwweeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrrrrrrrrrrrrrb
15
abcdefggegegegegegege
gegegegegddabacecevbbdbdnndnenjejje
16
diccionariosdeportugues
dcptgiowqqqaazzxxxx
17
b
c
18
kljfdsjfoieoijefnvnenvionewveinvewv
dkdjjshue
19
ooooooooooooopppppppppppppppppppppeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrrrrrrrrrrwwwwwwwwwwwwwwwwwwwtttttttttttttttttt
operwt
20
ooooooooooooopppppppppppppppppppppeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrrrrrrrrrrwwwwwwwwwwwwwwwwwwwtttttttttttttttttt
operwqzxcvbnmklo
21
ploploploploploploploploploploploploploploploploploploploploploploploploploploploploploploploploploploploploploploplo
jslkfsdjfsjfljfsdjfkdsjkjflkf
22
añoañoañoañoañoañoañoañoañoañoañoañoañoañoañoperuperuperuperuperuperuperuperuperuañoañoañoañoañoañoañoañoañoaño
añoperu
23
añoañoañoañoañoañoañoañoañoañoañoañoañoañoañoperuperuperuperuperuperuperuperuperuañoañoañoañoañoañoañoañoañoaño
ududududuudududupepeppewguqwhuihewhepqwehuwehwmncvmnnvmnvcnb
4
t
r
1
aaa
bcdbcdbcdbcdefghja
7
aaa
bcdbcdbcdbcdefdta
2
aaa
bcdbcdbcdbcdegt
1
cheese
ch
1
z
abcdef
1
aaa
bcdbcdbcdbcdefghja
7
aaa
bcdbcdbcdbcdefdta
2
aaa
bcdbcdbcdbcdegt
167
axyq
eprxibexxyf
171
nho
tonpyzwotkg
1
z
abcdef
1
abcdef
aghijklmcdefb
2
abcdef
abcdklmnoegfi
3
abcdef
abcklmnopdf
-1
Code: Select all
Round 1
You win.
Round 2
You chickened out.
Round 3
You lose.
Round 4
You chickened out.
Round 5
You lose.
Round 6
You chickened out.
Round 7
You chickened out.
Round 8
You lose.
Round 9
You chickened out.
Round 10
You win.
Round 11
You chickened out.
Round 12
You chickened out.
Round 13
You chickened out.
Round 14
You chickened out.
Round 15
You chickened out.
Round 16
You chickened out.
Round 17
You chickened out.
Round 18
You chickened out.
Round 19
You win.
Round 20
You lose.
Round 21
You chickened out.
Round 22
You win.
Round 23
You lose.
Round 4
You chickened out.
Round 1
You lose.
Round 7
You win.
Round 2
You chickened out.
Round 1
You chickened out.
Round 1
You chickened out.
Round 1
You lose.
Round 7
You win.
Round 2
You chickened out.
Round 167
You chickened out.
Round 171
You lose.
Round 1
You chickened out.
Round 1
You lose.
Round 2
You win.
Round 3
You chickened out.
Code: Select all
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
ArrayList<String> array = new ArrayList<String>();
ArrayList<String> arrayAux = new ArrayList<String>();
char correctWord [];
String tryWord;
boolean wiiin = false;
boolean looose = false;
int round;
int trie = 0;
int wrongTries = 0;
String win = "You win.";
String loose = "You lose.";
String pussy = "You chickened out.";
while((round = in.nextInt())!=-1){
correctWord=in.next().toCharArray();
tryWord=in.next();
for(int i=0; i<correctWord.length; i++){
array.add(Character.toString(correctWord[i]));
}
boolean aux = false;
String aux2 = "";
while(wrongTries < 7 && trie < tryWord.length() && wiiin == false){
aux2 = Character.toString(tryWord.charAt(trie));
while(array.remove(aux2)){
aux=true;
}
if(aux==false && !arrayAux.contains(aux2))
wrongTries++;
if(array.size()==0)
wiiin=true;
if(wrongTries == 7)
looose=true;
arrayAux.add(aux2);
aux=false;
trie++;
}
System.out.println("Round "+round);
if(wiiin)
System.out.println(win);
else if(looose)
System.out.println(loose);
else
System.out.println(pussy);
//System.out.println(array.toString());
array.clear();
arrayAux.clear();
wiiin = false;
looose = false;
trie = 0;
wrongTries = 0;
}
}
}
Code: Select all
2
cheese
abcdefg
Code: Select all
#include <stdio.h>
#include <string.h>
char word[200], inp[100], check[200];
int main()
{
int k, f, w, i;
while(scanf("%d ", &k) != EOF && k != -1)
{
memset(word, 0, sizeof(word));
memset(check, 0, sizeof(check));
gets(inp);
for(i = 0; inp[i]; ++i)
word[inp[i]] = 1;
gets(inp);
for(i = 0; inp[i]; ++i)
check[inp[i]] = 1;
for(i = 'a', w = f = 0; i <= 'z'; ++i)
if(check[i])
if(word[i])
word[i] = 0;
else ++w;
else if(word[i]) ++f;
printf("Round %d\n", k);
if(f)
if(w >= 7) puts("You lose.");
else puts("You chickened out.");
else puts("You win.");
}
return 0;
}
Code: Select all
1
cheese
chese
2
cheese
abcdefg
3
cheese
abcdefgij
1
aaa
bcdbcdbcdbcdefghja
-7
aaa
bcdbcdbcdbcdefdta
-2
aaa
bcdbcdbcdbcdegt
1
abc
bbbbbbbca
167
axyq
eprxibexxyf
171
nho
tonpyzwotkg
1
cheese
ch
1
z
abcdef
1
abcdef
ghijklm
-1
Round 1
You win.
Round 2
You chickened out.
Round 3
You lose.
Round 1
You win.
Round -7
You win.
Round -2
You chickened out.
Round 1
You win.
Round 167
You chickened out.
Round 171
You lose.
Round 1
You chickened out.
Round 1
You chickened out.
Round 1
You lose.
Code: Select all
1
a
qwertyua
Code: Select all
Round 1
You lose.