zoukankan      html  css  js  c++  java
  • 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
    奔跑吧!少年!趁着你还年轻
  • 相关阅读:
    第二月 day 2,内置函数
    第二月 day3 闭包,递归
    day4 装饰器
    第二月 day1生成器
    第一个月 总结
    day 16 迭代器
    day 15 编码
    Docker常用命令
    DRF源码刨析
    django中使用qiniu作为第三方存储
  • 原文地址:https://www.cnblogs.com/shu-xiaohao/p/3440108.html
Copyright © 2011-2022 走看看