#10857: 測資8怪怪的


tammy1 (呼)

學校 : 大同大學
編號 : 52335
來源 : [27.53.138.246]
最後登入時間 :
2021-05-20 13:29:55
c033. 00406 - Prime Cuts -- UVa406 | From: [118.161.15.138] | 發表日期 : 2016-04-13 21:54

#include<stdlib.h>
#include<stdio.h>

main(){
int prime[169]={1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997};

int N,C,i,j,p,k,m,n;
while(scanf("%d %d",&N,&C)!=EOF){
for(i=0;prime[i]<N;prime[i++]){}
printf("%d %d: ",N,C);

if(i%2==0) {
C=2*C;
p=i/2-1;//因為陣列是從0開始
if((C/2)-1>p){
for(k=p;k>0;k--){
printf("%d ",prime[p-k]);
//比大小 由小到大
}
}
else{
for(k=(C/2)-1;k>0;k--){
printf("%d ",prime[p-k]);
//比大小 由小到大
}
}
printf("%d ",prime[p]);
for(m=1;m<=(C/2)&&p+m<=i-1&&p+m<=168;m++){
if(prime[p+m]!=0) printf("%d ",prime[p+m]);
}
}
else {
C=(2*C)-1;
p=(1+i)/2-1;//因為陣列是從0開始
if(((C-1)/2)>p){
for(k=p;k>0;k--){
printf("%d ",prime[p-k]);
//比大小 由小到大
}
}
else{
for(k=((C-1)/2);k>0;k--){
printf("%d ",prime[p-k]);
//比大小 由小到大
}
}
printf("%d ",prime[p]);
for(m=1;m<=((C-1)/2)&&p+m<=168&&p+m<=i-1;m++){
if(prime[p+m]!=0) printf("%d ",prime[p+m]);
}
}
printf("\n\n");
}
return 0;
}

 

 

---

你的答案為 1 1: 2

正確答案為 1 1: 1

 

可是我用編譯器跑出來的是1 1: 1沒錯啊...

 
ZeroJudge Forum