求助。在本地没问题,但是在洛谷上全错
  • 板块P1781 宇宙总统
  • 楼主q_n_q
  • 当前回复3
  • 已保存回复3
  • 发布时间2023/1/4 23:32
  • 上次更新2023/10/24 05:33:01
查看原帖
求助。在本地没问题,但是在洛谷上全错
800102
q_n_q楼主2023/1/4 23:32
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <time.h>

bool cmp(char a[],char b[]){
    int lena=strlen(a),lenb=strlen(b);
    if(lena>lenb||lena==lenb&&strcmp(a,b)>0)return true;
    else return false;
}

int main(){
    int n,maxid=1;
    char max[101];
    scanf("%d",&n);
    fflush(stdin);
    gets(max);
    for(int i=2;i<=n;i++){
        char temp[101];
        gets(temp);
        if(cmp(temp,max)){
            strcpy(max,temp);
            maxid=i;
        }
    }
    printf("%d\n%s",maxid,max);
    return 0;
}
2023/1/4 23:32
加载中...