1170.找最小数

题目描述:

第一行输入一个数n,1 <= n <= 1000,下面输入n行数据,每一行有两个数,分别是x y。输出一组x y,该组数据是所有数据中x最小,且在x相等的情况下y最小的。 

输入:

输入有多组数据。
每组输入n,然后输入n个整数对。

输出:

输出最小的整数对。

样例输入:
5  
3 3  
2 2  
5 5  
2 1  
3 6
样例输出:
2 1
#include<iostream>
using namespace std;

int main(){
    int n,i,temp1,temp2;
    int a[1000];
    int b[1000];
    while(cin>>n){
        for(i=0;i<n;i++){
            cin>>a[i]>>b[i];
        }
        temp1=a[0];
        temp2=b[0];
        for(i=1;i<n;i++){
            if(temp1>a[i]){
                temp1=a[i];
                temp2=b[i];
            }
            else if(temp1==a[i]){
                if(temp2>b[i]){
                    temp2=b[i];
                }
            }
        }
        cout<<temp1<<" "<<temp2<<endl;
    }
    return 0;
}
原文地址:https://www.cnblogs.com/bernieloveslife/p/9735156.html