标题:最大回文数
用string写最大回文数
正解:1先判断他的位数,找出最大的位数,这样再按字典序排找出最大的数
我的思路一开始只是判断大小,后来发现死活不对,向博哥寻求了一波帮助,最后知道了是按字典序排大小比如9比132132132123213就大。
代码如下在这里插入代码片
#include<bits/stdc++.h>
using namespace std;
int f(string s) {
string s2;
int i;
s2=s;
reverse(s.begin(),s.end());
if(s==s2) {
return 1;
} else {
return 0;
}
}
int main() {
int n;
string s,s1,s2;
cin>>n;
int max=0;
int a[10009]= {0};
int k=1;
while(n–) {
cin>>s;
if(f(s))
{
if(s.length()>max)
{
s2=s;
max=s.length();
}
else if(s.length()==max)
{
if(s>s2)
{
s2=s;
}
}
}
}
cout<<s2;
return 0;
}