HUST Online Judge WebBoard
Problem 1115 >> 不知道错误在哪
201803140235 @ 2019-03-30 16:54:38
[ Quote ] [ Edit ] [ Delete ] 1#
for(i=0;i<n;i++)
for(j=0;j<n-i;j++)
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
排序的循环条件有问题
201803120204 @ 2019-04-16 19:41:34
[ Quote ] [ Edit ] [ Delete ] 2#
#include<stdio.h>
#include<math.h>
int sushu(int x)
{
int i,k;
if(x<2)
return (0);
k=sqrt(x);
for(i=2;i<=k;i++)
if(x%i==0)
break;
if(i>k)
return (1);
else return (0);
}
int main()
{
int n,k,i,a[100];
scanf("%d %d",&n,&k); //n->数目,k->第K个
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
if(sushu(a[k-1]))printf("YES\n");
else printf("NO");
printf("%d\n",a[k-1]);
}
运行错误,,我枯了
怎么错的,GG