Danny_chan @ 2023-10-28 20:27:23
哪位大佬能帮一下我
#include<bits/stdc++.h>
using namespace std;
string s;
bool hw(string s){
for(int i=0;i<s.size();i++){
if((s[i]-'0')!=(s[s.size()-1-i]-'0')){
return false;
}
}
return true;
}
int main(){
int a,b,f=0,sum=0;
cin>>a>>b;
for(int i=a;i<=a+30;i++){
s=to_string(i);
if(hw(s)){
f=1;
sum=i-a;
break;
}
}
if(f==1){
cout<<"STEP="<<sum;
}
else{
cout<<"Impossible!";
}
return 0;
}
by yyyyyyyyu @ 2023-11-24 20:36:53
int
不够,long long
也不够,需要用到高精度#include<bits/stdc++.h>
using namespace std;
int a[100001],b[100001],n,step,flag;
string s;
void add(int f2[],int f1[]) {
for(int i=1; i<=f2[0]; i++) {
f2[i]+=f1[i];
f2[i+1]+=f2[i]/n;
f2[i]%=n;
}
if(f2[f2[0]+1])f2[0]++;
}
void reverse(int a[],int b[]) {
for(int i=a[0]; i>=1; i--) {
b[a[0]-i+1]=a[i];
}
b[0]=a[0];
}
bool is_huiwen(int a[]) {
for(int i=1; i<=a[0]/2; i++) {
if(a[a[0]-i+1]!=a[i])return false;
}
return true;
}
int main() {
cin>>n>>s;
a[0]=s.size();
for(int i=1; i<=a[0]; i++) {
if(s[a[0]-i]>='A'&&s[a[0]-i]<='F')a[i]=s[a[0]-i]-'A'+10;
else a[i]=s[a[0]-i]-'0';
}
if(is_huiwen(a)) {
cout<<"STEP=1"<<endl;
return 0;
}
while(step<=30) {
step++;
reverse(a,b);
add(a,b);
if(is_huiwen(a)) {
cout<<"STEP="<<step<<endl;
return 0;
}
}
cout<<"Impossible";
return 0;
}
by Danny_chan @ 2023-11-25 21:54:23
谢谢大佬!
by Danny_chan @ 2023-11-27 20:41:45
不过程序怎么只有75分?