/ 科创班 /

记录详情

Wrong Answer

/in/foo.c: In function 'main':
/in/foo.c:12:19: warning: unused variable 'c' [-Wunused-variable]
 int num[N],number,c;
                   ^
/in/foo.c: In function 'input':
/in/foo.c:32:1: warning: 'gets' is deprecated [-Wdeprecated-declarations]
 gets(name[i]);
 ^~~~
In file included from /in/foo.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
/in/foo.c: In function 'sort':
/in/foo.c:45:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
     if(num[min]>num[j])
     ^~
/in/foo.c:47:3: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
   templ=num[i];
   ^~~~~
/tmp/ccBV01Ia.o: In function `input':
foo.c:(.text+0x51): warning: the `gets' function is dangerous and should not be used.
# 状态 耗时 内存占用
#1 Accepted 2ms 256.0 KiB
#2 Accepted 2ms 256.0 KiB
#3 Accepted 3ms 208.0 KiB
#4 Accepted 2ms 256.0 KiB
#5 Wrong Answer 2ms 256.0 KiB
#6 Accepted 2ms 256.0 KiB
#7 Accepted 3ms 256.0 KiB
#8 Accepted 2ms 256.0 KiB
#9 Accepted 3ms 256.0 KiB
#10 Accepted 3ms 256.0 KiB

代码

#include <stdio.h>
#include <string.h>
#define N 10
int n;

int main()
{
void input(int [],char name[][8]);
void sort(int [],char name[][8]);
void search(int,int[],char name[][8]);

int num[N],number,c;
char name[N][8];

scanf("%d %d",&n,&number);
input(num,name);
sort(num,name);
search(number,num,name);

return 0;
}

void input(int num[],char name[N][8])
{
int i;
for(i=0;i<n;i++)
{
//printf("inputNO.:");
scanf("%d",&num[i]);
//printf("input name:");
getchar();
gets(name[i]);
}
}

void sort(int num[],char name[N][8])
{
int i,j,min,templ;
char temp2[8];

for(i=0;i<n-1;i++)
{
min=i;
for(j=i;j<n;j++)
    if(num[min]>num[j])
		min=j;
		templ=num[i];
		strcpy(temp2,name[i]);
		num[i]=num[min];
		strcpy(name[i],name[min]);
		num[min]=templ;
		strcpy(name[min],temp2);
}
//printf("\nresult:\n");
for(i=0;i<n;i++)
    printf("%d %s\n",num[i],name[i]);
}

void search(int nm,int num[],char name[N][8])
{
int top,bott,mid,loca,sign;
top=0;
bott=n-1;
loca=0;
sign=1;
if((nm<num[0])||(nm>num[n-1]))
    loca=-1;
while((sign==1)&&(top<=bott))
{mid=(bott+top)/2;
if(nm==num[mid])
	{
	loca=mid;
	printf("%d %s",nm,name[loca]);
	//printf("NO. %d,his name is %s.\n",n,name[loca]);
	sign=-1;
	}
else if(nm<num[mid])
    bott=mid-1;
else
    top=mid+1;
}

if(sign==1||loca==-1)
printf("%d not been found.",nm);
}

信息

递交者
类型
递交
题目
7.15职工的排序与查找
题目数据
下载
语言
C
递交时间
2018-07-14 16:59:49
评测时间
2018-07-14 16:59:49
评测机
分数
90
总耗时
29ms
峰值内存
256.0 KiB