文章

5

粉丝

36

获赞

0

访问

923

头像
国名排序 题解:用结构体数组做,为什么答案不对呢,求解
P1217 同济大学机试题
发布于2024年3月20日 16:31
阅读数 156

#include<bits/stdc++.h>
using namespace std;
struct county{
    char name[100];
};
void paixv(county A[], int len){
    county tempt;
    for (int i = 0; i < len; i++){
        for (int j = 0; j < len - i - 1; j++){
            if (strcmp(A[j].name,A[j + 1].name)){//前面比后面大
                tempt = A[j];
                A[j] = A[j + 1];
                A[j + 1] = tempt;
            }
        }
    }
}
int main(){
    county ct[100];
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
  ...

登录查看完整内容


登录后发布评论

1 条评论
snake
2024年3月20日 19:21

strcmp函数返回结果>0

if (strcmp(A[j].name,A[j + 1].name) > 0){//前面比后面大

赞(0)