版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/SZU_Crayon/article/details/82184361
-
OpenJudge-合格的字符串
题目链接:1:合格的字符串
代码:
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main()
{
string *Answer;
string Request;
int num, begin, end;
cin >> num;
Answer = new string[num];
for (int i = 0; i < num; i++)
cin >> Answer[i];
cin >> Request;
begin = Request.find('[');
end = Request.find(']');
int Length = Request.length() - (end - begin);
begin++;
end--;
for (int i = 0; i < num; i++)
{
int flag = 0;
if (Answer[i].length() != Length)
continue;
for(int j=0;j<begin-1;j++) //左
if (Answer[i][j] != Request[j]&&fabs(Answer[i][j]- Request[j])!=32)
{
flag = 1;
break;
}
if (flag)
continue;
for (int j = end + 2; j < Length; j++) //右
if (Answer[i][j - (end - begin)] != Request[j] && fabs(Answer[i][j - (end - begin)] - Request[j]) != 32)
{
flag = 1;
break;
}
if (flag)
continue;
for (int j = begin; j <= end; j++) //中
{
if (Answer[i][begin - 1] == Request[j]||fabs(Answer[i][begin-1]-Request[j])==32)
{
cout << i + 1 << " " << Answer[i] << endl;
break;
}
}
}
return 0;
}