Pages

3/11/2014

Uva 10340 -All in All solution

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String m = new String();
while((m=br.readLine())!=null) {

String[] arr = m.split(" ");
char[] a = arr[0].toCharArray();
int start=0;
for(int i=0;i<a.length;i++) {
int k =arr[1].indexOf(a[i], start);

if(k > 0) {
start= k+1;
}
if (k==-1 || start > arr[1].length()) {
System.out.println("No");
break;
}
else if(i==a.length-1) {
System.out.println("Yes");
}

}
}
}

}

No comments :

Post a Comment