chengkelin2024 @ 2024-06-14 13:00:09
#include<bits/stdc++.h>
using namespace std;
int main(){
int sum=1000;
int d1,d2,d3,a,b;
cin>>a>>b;
int i = 0;
int palindrome[10000];
for (d1 = 1; d1 <= 9; d1+=2) { // 只有奇数才会是素数
for (d2 = 0; d2 <= 9; d2++) {
for (d3 = 0; d3 <= 9; d3++) {
palindrome[0+i] = 10000*d1 + 1000*d2 +100*d3 + 10*d2 + d1;//(处理回文数...)
i++;
sum++;
}
}
}
cin>>a>>b;
for(int i=1;i<=sum;i++){
if(palindrome[i]>=a&&palindrome[i]<=b){
cout<<palindrome[i];
}
}
return 0;
}
哪里错了谢谢
by MinimumSpanningTree @ 2024-06-14 13:09:50
@chengkelin2024 2 也是素数啊
by mc_xiexie @ 2024-06-14 13:11:50
@chengkelin2024
谁说回文数只有5位的
by chengkelin2024 @ 2024-06-14 13:11:50
@MinimumSpanningTree
要特判吗
by chengkelin2024 @ 2024-06-14 13:12:57
啥意思呀 我是个新手,教一下呗
by chengkelin2024 @ 2024-06-14 13:15:39
@mc_xiexie 啥意思
by mc_xiexie @ 2024-06-14 13:18:37
@chengkelin2024
你只生成了5位的回文数,但大于五位或小于五位的回文数就没有生成。
例如121就是一个3位的回文数
by chengkelin2024 @ 2024-06-14 13:18:38
#include<bits/stdc++.h>
using namespace std;
int main(){
int sum=1000;
int d1,d2,d3,a,b;
cin>>a>>b;
int i = 0;
int palindrome[10000];
for (d1 = 1; d1 <= 9; d1+=2) { // 只有奇数才会是素数
for (d2 = 0; d2 <= 9; d2++) {
for (d3 = 0; d3 <= 9; d3++) {
palindrome[0+i] = 10000*d1 + 1000*d2 +100*d3 + 10*d2 + d1;//(处理回文数...)
i++;
sum++;
}
}
}
cin>>a>>b;
for(int i=1;i<=sum;i++){
if(palindrome[i]>=a&&palindrome[i]<=b){
cout<<palindrome[i]<<endl;
}
}
return 0;
}
更改了,还是wa
by mc_xiexie @ 2024-06-14 13:21:00
@chengkelin2024 还有,数组开小了
by chengkelin2024 @ 2024-06-14 13:21:34
@mc_xiexie 那要怎么做呢
by mc_xiexie @ 2024-06-14 13:25:47
@chengkelin2024
循环判断