自定义函数
2023-09-16 09:44:09
发布于:浙江
#include <iostream>
using namespace std;
int pal(string s){
string s1;
int res = 0;
for(int i = s.length()-1;i >=0;i--){
s1 += s[i];
}
for(int i = 0;i < s.length();i++){
if(s[i] != s1[i]){
return 0;
}
}
return 1;
}
int what(string s){
for(int i = 0;i < s.length();i++){
if((s[i] >= 'A' && s[i] <= 'Z') || (s[i] >= 'a' && s[i] <= 'z')){
s[i] = '1';//let
}else{
s[i] = '0';//num;
}
}
int res = 0;//0str1num2let
for(int i = 0;i < s.length();i++){
if(s[i] == '1' && res == 1){
return 0;
}else if(s[i] == '0'&& res == 2){
return 0;
}else if(s[i] == '1'){
res = 2;
}else if(s[i] == '0'){
res = 1;
}
}
return res;
}
int main(){
string a,b;
cin >> a >> b;
int n;
cin >> n;
for(int i = 0;i < n;i++){
string s,temp;
cin >> s;
for(int j = 0;j < s.length();j++){
if(s[j] == 'a'){
temp += a;
}else{
temp += b;
}
}
cout << temp << endl;
if(pal(temp) == 1){
cout << "palindrome " ;
}else{
cout << "non-palindrome ";
}
if(what(temp) == 1){
cout << "number";
}else if(what(temp) == 2){
cout << "letter";
}else{
cout << "string";
}
cout << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个