第三个测试点有点小坑,具体看以下网址
https://blog.csdn.net/Yvonne_78/article/details/134039947
写了快一个小时,希望今年别遇到这种题,
#include <iostream>
using namespace std;
string x;
int n;
bool findNot( int i ){
if( i < 0 || i > x.size() - 1 ) return true;
char a = x[i];
if( a < '0' || ( a >'9' && a < 'A' ) || ( a > 'Z' && a < 'a' ) || a > 'z' ) return true;
else return false;
}
void Replace( string a, string b ){
int len1 = a.size();
int len2 = b.size();
for( int p = 0; p = x.find(a, p ), p != -1; p += len1 ){
if( findNot( p - 1 ) && findNot( p + len1 ) ){
x.erase( p, len1 );
x.insert( p, b);
}
}
}
int main(){
scanf("%d", &n );
getchar();
while( n -- ){
getline( cin, x );
cout << x << endl;
//去空格
while( x[0] == ' ' ) x.erase( 0, 1 );
while( x[x.size() - 1] == ' ' ) x.erase( x.size() - 1, 1 );
for( int i = 0; i < x.size(); i ++ ){
while( x[i] == ' ' && findNot( i + 1 ) ) x.erase( i , 1 );
}
//转换大小写
for( int i = 0; i < x.size(); i ++ ){
if( x[i] >= 'A' && x[i] <= 'Z' && x[i] != 'I' ) x[i] += ( 'a' - 'A' );
}
//替换
Replace( "I", "yoU" );
Replace( "me", "yoU" );
Replace( "can you", "I can" );
Replace( "could you", "I could" );
for( int i = 0; i < x.size(); i ++ ){
if( x[i] == '?' ) x[i] = '!';
}
for( int i = 0; i < x.size(); i ++ ){
if( x[i] >= 'A' && x[i] <= 'Z' && x[i] != 'I' ) x[i] += ( 'a' - 'A' );
}
cout << "AI: " << x << endl;
}
}