文章

5

粉丝

211

获赞

1

访问

7.2k

头像
找最小数 题解:
P1374 北京邮电大学机试题
发布于2023年5月10日 17:21
阅读数 616

因为只需要求一个最小数,我们不需要接受完数组再作操作,而是按照要求一边接受,一边判断最小值,最后直接输出即可。

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int x,y;
        int lastx,lasty;
        for(int i=0; i<n; i++)
        {
            scanf("%d %d",&x,&y);
            if(i==0)
            {
                lastx=x;
                lasty=y;
            }
            else
            {
                if(x<lastx)
                {
                    lastx=x;
                    lasty=y;

                }
                if(x==lastx && y<lasty)
                {
                    lastx=x;
                    lasty=y;

                }
            }
        }
        printf("%d %d\n",lastx,lasty);

    }
    return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发