Hoj 2991 Find the Point

来源:互联网 发布:阿里云盒子怎么刷机 编辑:程序博客网 时间:2024/05/22 08:12

本题也非常简单,主要练习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;}


原创粉丝点击