Unformatted text preview:

import java.io.*;import java.util.*;class shell { public static void main (String [] args) throws IOException { BufferedReader f = new BufferedReader(new FileReader("shell.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("shell.out"))); // UNCOMMENT THESE TWO LINES FOR TESTING AND COMMENT THE ABOVE TWO LINES //BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); //PrintWriter out = new PrintWriter(System.out); StringTokenizer st = new StringTokenizer(f.readLine()); int t = Integer.parseInt(st.nextToken()); int[] pos1 = new int[t]; int[] po+s2 = new int[t]; int[] guess = new int[t]; for(int i =0; i< t; i++) { st = new StringTokenizer(f.readLine()); int t1 = Integer.parseInt(st.nextToken()); int t2 = Integer.parseInt(st.nextToken()); int g1 = Integer.parseInt(st.nextToken());pos1[i] = t1-1; pos2[i] = t2-1; guess[i] = g1-1; } int score =0; int[] scores =new int[3]; for(int j =0; j< 3; j++) { int[] tr = {0,0,0}; tr[j] = 1; for(int i =0; i< t; i++) { int temp = tr[pos1[i]]; tr[pos1[i]]= tr[pos2[i]]; tr[pos2[i]] = temp; if(tr[guess[i]] == 1) { score++; } } scores[j] = score; score = 0; } int max = 0; for(int i =0; i<3; i++){ if (max< scores[i]) { max = scores[i]; } } out.println(max); out.close();


View Full Document

ATI CS 131 - Shellgame

Documents in this Course
Load more
Download Shellgame
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Shellgame and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Shellgame 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?