1 条题解

  • 0
    @ 2024-12-24 9:59:18

    C :

    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    main(){
    	int n,i,num,min1,min2,k1,k2;
    	while(scanf("%d",&n)!=EOF){
    		scanf("%d%d",&min1,&min2);
    		for(i=1;i<n;i++){
    			scanf("%d%d",&k1,&k2);
    			if(k1<min1){
    				min1=k1;
    				min2=k2;
    			}else if(k1==min1){
    				if(k2<min2){
    					min2=k2;
    				}
    			}
    		}
    		printf("%d %d\n",min1,min2);
    	}
    	return 0;
    }
    

    C++ :

    //北邮2010计算机:1170:找最小数
    //(1<=n<=1000)
    #include <fstream>
    #include <algorithm>
    #include <iostream>
    using namespace std;
    struct NUMBER{
    	int x, y;
    };
    NUMBER a[1000];
    
    bool cmp( NUMBER a, NUMBER b ){
    	if( a.x == b.x )
    		return a.y < b.y;
    	else return a.x < b.x;
    
    };
    
    int main()
    {
    	int i, j, k, n, m;
    		while( cin >> n ){
    		for( i=0; i<n; i++ )
    			cin >> a[i].x >> a[i].y;
    		sort(a,a+n,cmp);
    		cout << a[0].x << " " << a[0].y << endl;
    	}
    		return 0;
    }
    

    Java :

    
    
    import java.util.Arrays;
    import java.util.Scanner;
    
    public class Main {
       private static Scanner s = new Scanner(System.in) ;
       public static void main(String[] args) {
    	  while(s.hasNext()){
    		  int t = s.nextInt() ;
    		  Aa a[] = new Aa[t] ;
    		  for (int i = 0; i < t; i++) {
    			int x = s.nextInt() ;
    			int y = s.nextInt() ;
    			
    			a[i] = new Aa(x, y) ;
    		  }
    		  
    		  Arrays.sort(a) ;
    		  
    		  System.out.println(a[0].x+" "+a[0].y) ;
    	  }
        }
    }
    
    class Aa implements Comparable{
    	int x ;
    	int y ;
    	
    	
    	public Aa(int x, int y) {
    		super();
    		this.x = x;
    		this.y = y;
    	}
    
    
    	@Override
    	public int compareTo(Object o) {
    		Aa a = (Aa)o ;
    		
    		if(this.x<a.x){
    			return -1 ;
    		}else if(this.x==a.x){
    			if(this.y>a.y){
    				return 1 ;
    			}else if(this.y==a.y){
    				return 0 ;
    			}else return -1 ;
    		}
    		else return 1 ;
    	}
    }
    
    
    • 1

    信息

    ID
    1389
    时间
    1000ms
    内存
    32MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者