[Java] 纯文本查看 复制代码
import java.util.Scanner;
import java.util.HashMap;
class Answer3
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
sc.nextLine();
String[] strs = new String[m];
for(int i = 0 ; i < strs.length ; i ++ ) {
strs = sc.nextLine();
}
HashMap<String,String> map = new HashMap<String,String>();
String t1 = null, t2 = null;
for(int i = 0,l,r ; i < n ; i ++ ) {
t1 = sc.next();
t2 = sc.nextLine();
l = t2.indexOf('\"');
r = t2.lastIndexOf('\"');
t2 = t2.substring(l+1,r);
map.put(t1,t2);
}
for(int i = 0; i < strs.length ; i++ ) {
t1 = strs;
for(int j = 0,k ; j < t1.length() ; ) {
j = t1.indexOf("{{ ",j );
if( j == -1 )
break;
k = t1.indexOf(" }}",j+3 );
if( k == -1 )
break;
String key = t1.substring(j+3,k);
String value = map.get(key);
if( value == null )
value = "";
t1 = t1.substring(0,j) + value + t1.substring(k+3);
j = j + value.length();
}
strs = t1;
System.out.println(strs);
}
}
}