• CodeChef November Lunchtime 2013 Lucy and the Number Game(简单题)


    n个人报数找到只有一个报过且最小的数。

    代码如下:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <cstdlib>
     6 #include <algorithm>
     7 #define INF 0x7fffffff
     8 #define LEN 1000100
     9 using namespace std;
    10 
    11 struct P{
    12     char name[50];
    13     int num;
    14 }man[LEN];
    15 
    16 bool cmp(struct P a, struct P b){
    17     return a.num<b.num;
    18 }
    19 
    20 int main()
    21 {
    22 //    freopen("in.txt", "r", stdin);
    23 
    24     int T, n;
    25     scanf("%d", &T);
    26     while(T--){
    27         scanf("%d", &n);
    28         for(int i=1; i<=n; i++){
    29             scanf("%s%d", man[i].name, &man[i].num);
    30         }
    31         sort(man+1, man+n+1, cmp);
    32         int ans = -1, loc = man[1].num, cnt=1;
    33         for(int i=2; i<=n; i++){
    34             if(man[i].num == loc){
    35                 cnt++;
    36             }
    37             else {
    38                 if(cnt == 1){
    39                     ans = i-1;
    40                     break;
    41                 }else{
    42                     loc = man[i].num;
    43                     cnt = 1;
    44                 }
    45             }
    46         }
    47         if(cnt == 1 && loc == man[n].num) ans = n;
    48         if(ans!=-1)printf("%s
    ", man[ans].name);
    49         else printf("Nobody wins.
    ");
    50     }
    51     return 0;
    52 }
    View Code
    奔跑吧!少年!趁着你还年轻
  • 相关阅读:
    java基础
    C++菜鸟启动之旅--vc6.0使用教程详解
    第8章 Linux磁盘与文件系统管理
    IO(四)----对象的序列化
    IO(三)----序列流
    IO(二)----字符流
    IO(一)----字节流
    File类
    枚举类
    自动装箱和自动拆箱
  • 原文地址:https://www.cnblogs.com/shu-xiaohao/p/3440108.html
Copyright © 2020-2023  润新知