zoukankan      html  css  js  c++  java
  • (HDU)1234 -- 开门人和关门人

    题目链接:http://vjudge.net/problem/HDU-1234

    刚开始用了结构体觉得比较方便,后来想想,比较的时候临时变量也可以更新,可以不用结构体啊。

    贴的还是结构体代码:(其实come和left都可以用一个临时变量,我们要做的只是更新i,ans_1,ans_2就行)

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <cmath>
     4 #include <iostream>
     5 #include <algorithm>
     6 #include <string>
     7 #include <cstdlib>
     8 
     9 using namespace std;
    10 
    11 typedef struct
    12 {
    13     char id[100];
    14     int come;
    15     int left;
    16 }people;
    17 
    18 int main()
    19 {
    20     int t,i,n,hour,minute,second;
    21     people x[100];
    22     scanf("%d",&t);
    23     while(t--)
    24     {
    25         int early=1000000,late=0,ans_1,ans_2;
    26         scanf("%d",&n);
    27         for(i=1;i<=n;i++)
    28         {
    29             scanf("%s",x[i].id);
    30             scanf("%d:%d:%d",&hour,&minute,&second);
    31             x[i].come=3600*hour+60*minute+second;
    32             if(x[i].come<early)
    33             {
    34                 early=x[i].come;
    35                 ans_1=i;
    36             }
    37             scanf("%d:%d:%d",&hour,&minute,&second);
    38             x[i].left=3600*hour+60*minute+second;
    39             if(x[i].left>late)
    40             {
    41                 late=x[i].left;
    42                 ans_2=i;
    43             }
    44         }
    45         printf("%s %s
    ",x[ans_1].id,x[ans_2].id);
    46     }
    47     return 0;
    48 }
  • 相关阅读:
    C语言中for循环的使用
    详解C语言的main函数
    计算机语言的发展(the history of computer's language)
    hdu 1001
    hoj 1002
    hdu 1000
    POJ 1000(水题)
    hoj 1001
    code hunt题解(1)
    《C和指针》学习笔记(3)
  • 原文地址:https://www.cnblogs.com/ACDoge/p/6134087.html
Copyright © 2011-2022 走看看