2014-09-07

10115 - Automatic Editing




題目:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1056


import java.util.*;
import java.lang.*;


public class Main{
 public static int  times;
 public  static void main(String[] args) {
  Scanner keyin = new Scanner(System.in);
 while(keyin.hasNext()){ 
  
  int rulesNum = keyin.nextInt();
  keyin.nextLine();
 
  Rules[] stRules = new Rules[20];
  
  
  if(rulesNum==0)
   break;
  Rules rules ;
  for(int i=0 ; i<rulesNum ;i++){
   
   String find = keyin.nextLine();
   String replace = keyin.nextLine();
   rules = new Rules(find,replace);
   stRules[i] = rules;
  
   
  }
  
  
  String give = keyin.nextLine();
  System.out.println(search(stRules,give,rulesNum)); 
  }
 }
 public static String search(Rules[] stRule,String give,int rulesNum){
  StringBuilder editedText = new StringBuilder(give);
  for(int i=0 ; i<rulesNum ; i++){
   int findIndex = editedText.indexOf(stRule[i].find);
   while(findIndex!=-1){
    editedText.delete(findIndex, findIndex+(stRule[i].find).length());
    editedText.insert(findIndex,stRule[i].replace);
    findIndex = editedText.indexOf(stRule[i].find);
   }
  }
  return editedText.toString();
 }
 
 }

class Rules {
 
 public  String find="";
 public  String replace="";
 public Rules(String find,String replace){
  this.find = find;
  this.replace=replace;
 }
 
   
 
}

沒有留言:

張貼留言

(VM) Ubuntu enable ssh

OS版本:14.04 LTS 相關指令: sudo apt-get install openssh-server Port forwarding設定 : 以virtual box為例子,網路->進階->連接阜轉送(port forwarding) ...