hi ... i'm starting to solve usaco problems and i'm a beginner....
so the problem is easy .... or hard i dont know
for the first program (friday 13th) it gives me an output of array with zeros which i tried to debug with (print) to see the variables' changes (as i learned here) and my conclusion is that the loop (for) doesn't work !! and this is the part that i can't solve really .....
for the second program the greedy gift giver it gives an empty output.....
thx
and now Greedy gift giver program !!package friday; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.*; public class friday { /** * @param args the command line arguments */ public static void main(String[] args)throws IOException { int[] array = new int[7] ; int ini = 3 ; int a=0 , b , c , d , e , f , g , h ; int n , i ; Scanner s = new Scanner(new File("friday.in")); PrintWriter pw = new PrintWriter(new File("friday.out")); n = s.nextInt() ; for (i=0 ; i == n-1 ; i++ ) { if ((i%4)==0) { a= ((ini+5) % 7) ; b = ((ini+9)%7) ; c = ((ini+4)%7) ; d = ((ini+1)%7) ; e = ((ini+7)%7) ; f= ((ini+3)%7) ; array[a] = array[a]+1 ; array[b] = array[b]+1 ; array[c] = array[c]+4; array[d] = array[d]+1 ; array[e] = array[e]+4 ; array[f] = array[f]+1 ; ini = (ini + 6)%7 ; } else a= ((ini+5) % 7) ; b = ((ini+9)%7) ; c = ((ini+4)%7) ; d = ((ini+1)%7) ; e = ((ini+7)%7) ; f= ((ini+3)%7) ; g = ((ini+6)%7) ; h = ((ini+2)%7) ; array[a] = array[a]+1 ; array[b] = array[b]+1 ; array[f] = array[f]+2 ; array[e] = array[e]+3 ; array[g] = array[g]+4 ; array[h] = array[h]+1 ; ini = (ini + 5)%7 ; } a= ((ini+5) % 7) ; pw.print(array[0] + " " + array[1]+ " " + array[2]+ " " + array[3]+ " " + array[4]+ " " + array[5]+ " " + array[6]+ " ") ; pw.print(a) ; pw.close(); s.close() ; } }
import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.*; public class gift1 { public static void main(String[] args) throws IOException { Scanner s = new Scanner(new File("gift1.in")); PrintWriter pw = new PrintWriter(new File("gift1.out")); String p , giver = null , taker ; int i , np , k , j ,h,total, no , calc,temp; np = s.nextInt() ; String names[] = new String[np] ; Hashtable <String , Object> table = new Hashtable<String, Object>(); for (i = 2; i == (np + 1); i++) { p = s.next(); names[i-2] = p ; table.put(p,0) ; } for (k = 1; k == np; k++) { giver = s.next() ; total = s.nextInt(); no = s.nextInt() ; for (j=1 ; j == no ; j++){ if (no==0) break ; else taker = s.next() ; calc = ((total-(total%no))/no) ; temp = Integer.parseInt(table.get(taker).toString()) ; temp = temp + calc ; table.put(taker , temp) ; temp = Integer.parseInt(table.get(taker).toString()) ; temp = temp - calc ; table.put(giver , temp) ; } } for(h=0 ; h<np ; h++ ) { pw.print(names[h]) ; giver = names[h] ; pw.print(table.get(giver)) ; } pw.close(); s.close(); } }