提交记录 #505
提交时间:2024-12-17 13:18:38
语言:c
状态:Accepted
编译情况:编译成功
code.c: In function ‘main’:
code.c:18:4: warning: implicit declaration of function ‘gets’; did you mean ‘fgets’? [-Wimplicit-function-declaration]
18 | gets( sa );
| ^~~~
| fgets
code.c: In function ‘number’:
code.c:38:13: warning: implicit declaration of function ‘strtok’ [-Wimplicit-function-declaration]
38 | token = strtok(str, " ");
| ^~~~~~
code.c:38:11: warning: assignment to ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
38 | token = strtok(str, " ");
| ^
code.c:40:20: warning: implicit declaration of function ‘atoi’ [-Wimplicit-function-declaration]
40 | a[i].num = atoi(token);
| ^~~~
code.c:43:15: warning: assignment to ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]
43 | token = strtok(NULL, " ");
| ^
/usr/bin/ld: /tmp/ccZjG3ZL.o: in function `main':
code.c:(.text.startup+0x1c): warning: the `gets' function is dangerous and should not be used.
固定测试点暂不可用
附加测试点暂不可用
5959-64,H26
int number(char *str, DATA a[]) {
int i = 0, j = 0, k = 0;
char *token;
int count = 0;
token = strtok(str, " ");
while (token != NULL && i < 100) {
a[i].num = atoi(token);
a[i].no = 0;
i++;
token = strtok(NULL, " ");
}
count = i;
DATA sorted[100];
for (j = 0; j < count; j++) {
sorted[j] = a[j];
}
for (j = 0; j < count - 1; j++) {
for (k = 0; k < count - 1 - j; k++) {
if (sorted[k].num > sorted[k + 1].num) {
DATA temp = sorted[k];
sorted[k] = sorted[k + 1];
sorted[k + 1] = temp;
}
}
}
for (j = 0; j < count; j++) {
for (k = 0; k < count; k++) {
if (sorted[j].num == a[k].num && a[k].no == 0) {
a[k].no = j + 1;
break;
}
}
}
return count;
}