ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1581. Teamwork

WA #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
Posted by ctorres.vsm 26 Nov 2015 06:04
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);