http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1394

1394: Virus Replication

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 135  Solved: 40
[Submit][Status][Web Board]

Description

csuoj 1394: Virus Replication-LMLPHP

Input

csuoj 1394: Virus Replication-LMLPHP

Output

csuoj 1394: Virus Replication-LMLPHP

Sample Input

AAAAA
AGCGAA

Sample Output

3

HINT

csuoj 1394: Virus Replication-LMLPHP

Source

分析;
题目意思是找出在第一个串中第二个串没有出现的字母个数,要求从前往后遍历和从后往前遍历两次。

AC代码:

 #include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<iostream>
#include<stack>
#include<map>
#include<string>
using namespace std;
char ch1[], ch2[];
int main(){
int n, a, b;
while(~scanf("%s%s", ch1, ch2)){
int l1 = strlen(ch1);
int l2 = strlen(ch2);
a = ;
b = l2-;
for(int i = ; i < l1 && i < l2; i++){
if(ch1[i] == ch2[i]){
a = i+;
ch1[i] = '#'; //避免重复判断
}
else
break;
}
for(int i = ; i <= l1&&i <= l2;i++){
if(ch1[l1-i] == ch2[l2-i]){
b = l2-i-;
}
else
break;
}
if(a > b)
printf("0\n");
else
printf("%d\n", b-a+);
}
return ;
}
05-11 11:27