2016年7月11日 星期一

Q10340: All in All


https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1281

import java.util.*;

public class Main {

 public static void main(String[] args) {
  Scanner scn = new Scanner(System.in);
  while (scn.hasNext()) {
   String str1 = scn.next(), str2 = scn.next();
   char s[] = str1.toCharArray(), t[] = str2.toCharArray();
   int i, j, n = 0;
   for (i = 0; i < s.length; i++) {
    boolean c = true;
    for (j = n; j < t.length; j++, n++) {
     if (s[i] == t[j]) {
      c = false;
      n++;
      break;
     }
    }
    if (c) {
     System.out.println("No");
     break;
    }
   }
   if (i == s.length)
    System.out.println("Yes");

  }
 }
 /* 
    題目:Q10340: All in All
    作者:1010
    時間:西元 2016 年 7 月 */
}


困難度 
這題要注意的是找到字後要n++不然當測資faa aceecbeeffaeeced 會Yes(答案No)

沒有留言:

張貼留言