(UVA) 10115 - Automatic Editing - Solução


import java.io.*;
import java.util.*;
import java.lang.Math;
import java.math.*;

class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
        Main processando = new Main();
        processando.takeInput();
       
        System.exit(0);
    }
   
    void takeInput() throws NumberFormatException, IOException {
        String line = "";
       
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       
        while ((line = br.readLine()) != null) {
            if (Integer.valueOf(line) == 0) {
                return;
            }
           
            Integer qteRegras = Integer.valueOf(line);
           
            ArrayList<String> vetorRegra = new ArrayList<String>();
            ArrayList<String> vetorSubst = new ArrayList<String>(); 
             
            for (int i = 0; i < qteRegras; i++) {
                vetorRegra.add(br.readLine());
                vetorSubst.add(br.readLine());   
            }
           
            String frase = br.readLine();  
                       
            String novaFrase = frase;
            for (int j = 0; j < qteRegras; j++) {
                do {
                    frase = novaFrase;
                    novaFrase = frase.replaceFirst(vetorRegra.get(j), vetorSubst.get(j));
                } while (frase.compareTo(novaFrase) != 0);
            }
           
            System.out.println(novaFrase);          
        }
       
        return;
    }
}

Comments

Popular posts from this blog

(Coderbyte) Powers of Two - Solução

(Coderbyte) Dash Insert II - Solução

(CoderByte) Number Search - Solução