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 1510. Order

WA C++ AND Time limit JAVA & C#. Please Help
Posted by Gregory 13 Nov 2012 00:29
Why WA?

#include <iostream>
using namespace std;
void main(){
    int x;
    int y;
    int jb = 0, jc = 0;
        cin >> x;
        //int mass[x];
        int *mass = new int[x];
        int *mass2 = new int[x];
        int *mass3 = new int[x];

        for(int i=0;i<x;i++){
            cin >> y;
            mass[i] = y;
        }

        for(int i=0, j=0, p=0;i<x;i++, j=0, p=0){
            if(mass[i] == 0){
                continue;
            }
            for(;j<x;j++){
                if(mass[j] == 0){
                continue;
            }
                if(mass[i]==mass[j]){
                    p++;
                    if(i!=j){
                    mass[j]=0;
                    }
                }
            }
            mass2[i] = p;
            mass3[i] = mass[i];
            if(jb<=mass2[i]){
                jb=mass2[i];
                jc=i;
            }
        }
        cout << mass3[jc];
}

AND JAVA How make this program faster?
import java.util.*;

public class Uno {
    public static void main(String[] args){
        int jb = 0, jc = 0;
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int[] mass = new int[x];
        int[] mass2 = new int[x];
        int[] mass3 = new int[x];

        for(int i=0;i<mass.length;i++){
            int y = in.nextInt();
            mass[i] = y;
        }

        for(int i=0, j=0, p=0;i<mass.length;i++, j=0, p=0){
            if(mass[i] == 0){
                continue;
            }
            for(;j<mass.length;j++){
                if(mass[j] == 0){
                    continue;
                }
                if(mass[i]==mass[j]){
                    p++;
                    if(i!=j){
                    mass[j]=0;
                    }
                }
            }
            mass2[i] = p;
            mass3[i] = mass[i];
            if(jb<=mass2[i]){
                jb=mass2[i];
                jc=i;
            }
        }
        System.out.print(mass3[jc]);
    }
}

OR C#
using System;

public class Uno
{
    public static void Main(String[] args)
    {
        string x; string y;
        int jb = 0, jc = 0;
        x = Console.ReadLine();
        int[] mass = new int[int.Parse(x)];
        int[] mass2 = new int[int.Parse(x)];
        int[] mass3 = new int[int.Parse(x)];

        for (int i = 0; i < int.Parse(x); i++)
        {
            y = Console.ReadLine();
            mass[i] = int.Parse(y);
        }

        for (int i = 0, j = 0, p = 0; i < int.Parse(x); i++, j = 0, p = 0)
        {
            if (mass[i] == 0)
            {
                continue;
            }
            for (; j < int.Parse(x); j++)
            {
                if (mass[j] == 0)
                {
                    continue;
                }
                if (mass[i] == mass[j])
                {
                    p++;
                    if (i != j)
                    {
                        mass[j] = 0;
                    }
                }
            }
            mass2[i] = p;
            mass3[i] = mass[i];
            if (jb <= mass2[i])
            {
                jb = mass2[i];
                jc = i;
            }
        }
        Console.Write(mass3[jc]);
    }
}