Rezultati

Up. imeNalogaJezikRezultatČas oddaje
pokosimo-2018 Prehitevanje Java 0/100Prekoračen čas (TLE) 04. okt '18 @ 20:13

Test Točke Porabljen spomin Porabljen čas Status
#1 16/16 37,184 MiB 0,000 s OK
#2 16/16 47,223 MiB 0,000 s OK
#3 17/17 40,242 MiB 0,000 s OK
#4 0/17 141,953 MiB 4,168 s Prekoračen čas
#5 0/17 163,418 MiB 6,741 s Prekoračen čas
#6 17/17 37,242 MiB 0,000 s OK

Ocenjevani program (Vaja3.java):
import java.util.*;
import java.lang.Math;
public class Vaja3 {
    public static String[] zamenjaj1 (String[] t, int i1, int i2, String a, String b){
        String[] nt = new String[t.length];
        int i = 0;
        while(i<i1){
            nt[i]=t[i];
            i++;
        }
        while(i<i2-1){
            nt[i]=t[i+1];
            i++;
        }
        nt[i++]=a;
        while(i<t.length){
            nt[i]=t[i];
            i++;
        }
        return nt;
    }

    public static String[] zamenjaj2 (String[] t, int i1, int i2, String a, String b){
        String[] nt = new String[t.length];
        int i = 0;
        while(i<i2){
            nt[i]=t[i];
            i++;
        }
        nt[i++]=a;
        while(i<i1+1){
            nt[i]=t[i-1];
            i++;
        }

        while(i<t.length){
            nt[i]=t[i];
            i++;
        }
        return nt;
    }

    public static void main (String args[]){
        Scanner sc = new Scanner(System.in);
        int stTek = sc.nextInt();
        String[] t = new String[stTek];
        for (int i=0; i<stTek; i++){
            t[i]=sc.next();
        }
        
        int stPreh = sc.nextInt();
        for (int i=0; i<stPreh; i++){
            String a = sc.next();
            String b = sc.next();
            int x = 2, ix1=-1, ix2=-1, j=0;
            while(x>0){
                if (a.equals(t[j])){
                    ix1=j;
                    x--;
                } else if (b.equals(t[j])){
                    ix2=j;
                    x--;
                }
                j++;
            }
            if (ix1<ix2){
                t = zamenjaj1(t, ix1, ix2, a, b);
            }
            if (ix2<ix1)
                t = zamenjaj2(t, ix1, ix2, a, b);
        }
        //izpis
        for (int i=0; i<stTek; i++){
            System.out.println(t[i]);
        }
    }
}
// 6 g c n f h p 1 p c