大佬们来看一看,样例没有问题,但是全错误

P5741 【深基7.例10】旗鼓相当的对手 - 加强版

`<=5` 放在括号外面
by lzm0107 @ 2024-02-06 15:32:39


```c #include<stdio.h> #include<stdlib.h> #include<string.h> struct student { char name[10]; int a,b,c; int sum; }stu[1005]; int main() { int n; scanf("%d", &n ); // 录入数据; for ( int i = 0; i < n; i++ ) { scanf("%s %d %d %d", stu[i].name, &stu[i].a, &stu[i].b, &stu[i].c ); stu[i].sum = stu[i].a + stu[i].b + stu[i].c; } for ( int i = 0; i < n; i++ ) { for ( int j = i+1; j < n; j++ ) { if ( abs(stu[i].a - stu[j].a) <= 5 && abs(stu[i].b - stu[j].b ) <= 5 && abs(stu[i].c - stu[j].c ) <= 5 && abs(stu[i].sum - stu[j].sum ) <= 10 ) { if ( strcmp(stu[i].name,stu[j].name) < 0 ) { printf("%s %s\n", stu[i].name, stu[j].name ); } else { printf("%s %s\n", stu[j].name, stu[i].name ); } } } } return 0; } ```
by lzm0107 @ 2024-02-06 15:33:30


@[lv123123](/user/1260096)
by lzm0107 @ 2024-02-06 15:33:45


@[lzm0107](/user/555994) 谢谢大佬!看了好久- -
by lv123123 @ 2024-02-06 15:40:23


@[lzm0107](/user/555994) ``` if ( strcmp(stu[i].name,stu[j].name) < 0 ) { printf("%s %s\n", stu[i].name, stu[j].name ); ``` 能告诉我这是干什么吗?
by zrj2012 @ 2024-03-30 15:21:08


@[zrj2012](/user/1277913) > 输出时也应该按照字典序输出所有对手组合。
by lzm0107 @ 2024-03-30 15:23:24


@[lzm0107](/user/555994) 哦,谢谢
by zrj2012 @ 2024-03-30 15:29:50


|