简单的题解
2026-05-09 21:21:15
发布于:北京
4阅读
0回复
0点赞
代码:
#include <iostream>
#include <string>
using namespace std;
bool pal(string s) {
for(int i = 0,j = s.size() - 1;i <= j;i++,j--) {
if(s[i] != s[j]) return false;
}
return true;
}
string pd(string s) {
bool h1 = false,ha = false;// 有数字 有字母
for(int i = 0;i < s.size();i++) {
if(s[i] >= '0' && s[i] <= '9') h1 = true;
else ha = true;
if(h1 & ha) break;
}
if(h1 & ha) return "string";
else if(h1) return "number";
return "letter";
}
int main() {
string s1,s2;
cin >> s1 >> s2;
int t;
cin >> t;
while(t--) { // 循环n次
string s;
cin >> s;
string now = "";
for(char c : s) {
if(c == 'a') now += s1;
else now += s2;
}
cout << now << endl;
if(pal(now)) cout << "palindrome ";
else cout << "non-palindrome ";
cout << pd(now) << endl;
}
return 0;
}
简单,分别判断是否回文,是否包含数字字母即可
给!个!赞!吧!
这里空空如也







有帮助,赞一个