7-2 串的模式匹配 (20 分)
给定一个主串S和一个模式T,要求在主串S中找出与模式T相匹配的子串,返回相匹配的子串中的第一个字符在主串S中出现的位置。
输入格式:
输入有两行: 第一行是主串S; 第二行是模式T.
输出格式:
输出相匹配的子串中的第一个字符在主串S中出现的位置。若匹配失败,输出0.
输入样例:
在这里给出一组输入。例如:
aaaaaba
ba
输出样例:
在这里给出相应的输出。例如:
6
#include <iostream>
#include <cstdio>
#include <math.h>
#include <string.h>
#include <string>
#include <algorithm>
#include <stack>
#include <list>
#include <vector>
#include <set>
using namespace std;
typedef long long ll;
int main(){
ios::sync_with_stdio(false);
string s1,s2;
cin>>s1>>s2;
if(s1.length() < s2.length()){
cout<<0<<endl;
}
else if(s1.length() == s2.length()){
if(s1 == s2){
cout<<1<<endl;
}
else{
cout<<0<<endl;