Problem B. Problem Select (atoi()函数)

Problem B. Problem Select
Input file: standard input
Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes
HOJ is an online judge system for students in HIT to practice. As the administrator, you would always
setup contests by selecting problems from the problem set. Problem IDs are integers that can be phased
by url. For example, the corresponding problem ID of url http://acm.hit.edu.cn/problemset/1001
is 1001.
Now the task is, given n urls, print the smallest k problem IDs in increasing order.
Input
The first line of the input contains one integer T (1 ≤ T ≤ 10), indicating the number of test cases.
For each test case, the first line contains two integers, n (1 ≤ n ≤ 1000) and k (1 ≤ k ≤ n).
For the next n lines, each line contains a string indicating the problem’s url. The problem ID is guaranteed
to be in range [1, 10000] and unique in each case.
Output
Output T lines.
For each test case, you should output k numbers in a line, and there shouldn’t be any spaces at the end
of the line.
Example
standard input
2
3 2
http://acm.hit.edu.cn/problemset/1003
http://acm.hit.edu.cn/problemset/1002
http://acm.hit.edu.cn/problemset/1001
4 1
http://acm.hit.edu.cn/problemset/1001
http://acm.hit.edu.cn/problemset/2001
http://acm.hit.edu.cn/problemset/3001
http://acm.hit.edu.cn/problemset/501
standard output
1001 1002
501

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int a[10010];
    char s[110];
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        scanf("%d %d",&n,&m);
        getchar();
        for(int i=1;i<=n;i++)
        {
            scanf("%s",s);
            int x=atoi(s+33);
            a[i]=x;
        }
        sort(a+1,a+n+1);
        for(int i=1;i<m;i++)
         printf("%d ",a[i]);
         printf("%d\n",a[m]);;

    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值