|
|
back to boardWA #5 JAVA, SOMEONE CAN HELP ME? HERE IS MY CODE Posted by Julius 26 Nov 2015 05:45 import java.io.PrintWriter; import java.util.Scanner; public class P1581 { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); int [] vec=new int[n]; for(int i=0;i<n;i++)vec[i]=in.nextInt(); int cont=0,num; num=vec[0]; for(int i=0;i<n;i++){ if(vec[i]==num){ cont=cont+1; } if(vec[i]!=num || i+1==n){ if(i+1!=n){ System.out.printf("%d %d ",cont,num); }else{ System.out.printf("%d %d",cont,num); } num=vec[i]; cont=1; }
} out.flush(); } } ---- THANKS YOU, GREETINGS. Edited by author 26.11.2015 05:45 Re: WA #5 JAVA, SOMEONE CAN HELP ME? HERE IS MY CODE nub qlo int cont=0,num; num=vec[0]; for(int i=0;i<n;i++){ if(vec[i]==num){ cont=cont+1; } if(vec[i]!=num ){ System.out.printf("%d %d ",cont,num); num=vec[i]; cont=1; } } System.out.printf("%d %d",cont,num); |
|
|