Hoj 2991 Find the Point

本题也非常简单,主要练习sscanf()使用,以及sort()排序。

题目:http://acm.hit.edu.cn/hoj/problem/view?id=2991


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;

struct point
{
    char s[100];
    double x;
    double y;
};

point p[102];

//从小到大排序
bool cmp(point a,point b)
{
    return (a.y<b.y) || (a.x == b.x && a.y<b.y);
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
#endif
    int t;
    int n;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%s",p[i].s);
            sscanf(p[i].s," (%lf,%lf)",&p[i].x,&p[i].y);
        }
        sort(p,p + n,cmp);
        printf("%s %s\n",p[n-1].s,p[0].s);
    }
    return 0;
}




你可能感兴趣的:(Hoj 2991 Find the Point)