Recent brush title

Beijing University of Posts hospital computer on retest machine Zhenti PubMed:
questions to find a minimum number.
The first input line of a number n, 1 <= n <= 1000, the following input data line n, there are two numbers in each row, are XY. Outputs a set of xy, the set of data is the smallest of all the data x, and in case of equality x y minimum.
Input Description:
Enter multiple sets of data.
Each input n, and the input n integers pairs.
Description Output:
output the smallest integer pair.
Example 1
Input:

5  
3 3  
2 2  
5 5  
2 1  
3 6

Output:

2 1

2. Analysis: found based on questions intended: this question requires a set of data, find the smallest number in a column and the data in the column to ensure a minimum number of the corresponding line to obtain a minimum number. Therefore, the most effective way that the use of sorting operation. However, although at first I used the sort ordering, but although the code can be test cases, but can not pass a background test cases, and later learned that need to use the sort using the structure struct sort.
3. execute the code:

#include<bits/stdc++.h>
using namespace std;
    struct shuju{
    int x;
    int y;
}student[1000];//先定义struct结构体,并且在结构体中存放行、列数据
bool compare(shuju b1,shuju b2){\\应注意,使用结构体的sort排序时,不能将该算法直接使用,而是需要将该结构体的compare排序函数另行写出,详情可参见网上struct排序模板
    if(b1.x==b2.x){
        return b1.y<b2.y;
    }
    else{
        return b1.x<b2.x;
    }
}
int main()
{
    int n,i;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>student[i].x>>student[i].y;
    }
    sort(student+0,student+n,compare);//调用struct排序函数,排序完毕之后,直接取第一组行列数据即可!
    cout<<student[0].x<<" "<<student[0].y<<endl;
    return 0;
}

4. Run the right shots:

. Find one decimal two questions k
find an array of small numbers of K, pay attention to the same size as large operators. As 213,452 third decimal 3.
Input Description:
Enter multiple sets of data.
Each input n, and the input n integers (1 <= n <= 1000 ), then the input k.
Output Description:
Small integers k-th output.
Example 1
Input

6
2 1 3 5 2 2
3

Export

3

2. Analysis: Initially conceivable to use to sort a set of data processing is completed, and directly to the k-th digital output, however, the problem that is found - once data is repeated, taking into account the need to re-condition, thus also We need to think more!
3. Code Execution

#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int main()
{
    int n,i,a[100];
    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a + 0, a + n);
    int t;
    cin >> t;//输入要查找的第k个小数
    {
        
        for (i = 0; i < n; i++) {
            if (a[i] != a[i - 1]) {//进行去重,一旦发现后一个与前一个不一样大
                t--;//即使用t对数据进行逐个进行递减地标记,例如测试用例中:排序后为122235,第一个数就用t标记为2,第二个数就用t标记为1,第三个数就用t标记为1,往后同理...到第五个数就用t标记为0
                if (t == 0) {//到此即符合要查找的第k个数,输出即可
                    cout<<a[i]<<endl;break;
                }
            }
        }
    }
}

4. Run correctly screenshot

questions III. Comparison of the number of odd number
of the first input line of a number of n, a second input line number n, in which n number, the even more than if odd, outputting to NO, output YES.
Input Description:
Enter multiple sets of data.
Each input n, and the input n integers (1 <= n <= 1000 ).
Output Description:
If an even number more than the odd output to NO, output YES.
Example 1

输入
5
1 5 2 4 3
输出
YES

2. Analysis: problem on board a group of the easiest questions, serious water problem, the code can be directly attached! (Ps: Java over title)
3. Code Execution

import java.util.Scanner;
public class Main {
    private static Scanner in;
    public static void main(String[] args) {
    in=new Scanner(System.in);
    int n,i,x=0,y=0;
    int a[]=new int[100];
    n=in.nextInt();
    for(i=0;i<n;i++) {
        a[i]=in.nextInt();
        if(a[i]%2==0) {
            x++;
        }
        else {
            y++;
        }
    }
    if(x>y) {
        System.out.print("NO");
    }
    else if(x<y||x==y) {
        System.out.print("YES");
    }
}
}

4. Run the right shots:

a total of 13 questions, you can do out of three, and the remaining 10 questions continue efforts to study the ~ ~, the third title for the fifth time over the question of the use of Java, incidentally familiar with Java the basic syntax, the latter continue to fuel 8, turn off the lights to sleep ( ﹃~ ~) ~ zZ ......

Guess you like

Origin www.cnblogs.com/wonzenkei/p/11921012.html