RE*N

B4039 [GESP202409 三级] 回文拼接

Yangshuhao123 @ 2024-12-06 22:37:24

#include<bits/stdc++.h>//iostream
using namespace std;
int n;
bool f;
string x;
bool Huewen(string x){
    char a[110]={0};
    int cnt=0; 
    for(int i=x.size()-1;i>=0;i--)
     a[cnt++] = x[i];
    for(int i=0;i<x.size();i++)
     if(a[i] != x[i])
      return 0;
    return 1;
}
int main(){
    cin>>n;
    while(n--){
        f=0;
        cin>>x;
        for(int i=1;i<x.size()-2;i++)
         if(Huewen(x.substr(0,i+1))&&Huewen(x.substr(i+1))){
            cout<<"Yes"<<endl;
            f=1;
            break;
         }
        if(f==0)
         cout<<"No"<<endl;
    }
    return 0;
}

by lsrlsrlsr @ 2024-12-15 11:11:29

size()返回的是无符号整形,不能是负数,否则RE


by lsrlsrlsr @ 2024-12-15 11:14:37

#include<bits/stdc++.h>//iostream
using namespace std;
int n;
bool f;
string x;
bool Huewen(string x){
    if(x.size()<2){
        return 0;
    }
    char a[110]={0};
    int cnt=0;
    for(int i=x.size()-1;i>=0;i--)
     a[cnt++] = x[i];
    for(int i=0;i<x.size();i++)
     if(a[i] != x[i])
      return 0;
    return 1;
}
int main(){
    cin>>n;
    while(n--){
        f=0;
        cin>>x;
        for(int i=1;i<x.size();i++){
             if(Huewen(x.substr(0,i+1))&&Huewen(x.substr(i+1))){
                cout<<"Yes"<<endl;
                f=1;
                break;
             }
        }
        if(f==0)
         cout<<"No"<<endl;
    }
    return 0;
}

函数加个判断就过了 ~~求关


by lsrlsrlsr @ 2024-12-15 11:15:10

@Yangshuhao123


by Yangshuhao123 @ 2024-12-18 22:44:33

@lsrlsrlsr Thanks


|