幸运名单
Time Limit: 1000 ms Memory Limit: 65536 KiB
Submit Statistic
Problem Description
咸鱼公司最近要从参与产品调查的 n 位用户中随机抽取 m 位发放幸运奖品,不过最近公司里的程序员们都咸鱼了,所以他们来找你帮忙写一个程序,根据已经随机出的幸运用户编号输出幸运用户名单。
Input
输入数据有多组(数据组数不超过 100),到 EOF 结束。
对于每组数据:
第 1 行输入 1 个整数 n (1 <= n <= 100) 表示名单中的人数
接下来有 n 行,每行输入一个人的信息,格式为 “姓名 联系方式”,姓名是不含空格且长度不超过 10 的字符串,联系方式是不含空格且长度不超过 30 的字符串
下面 1 行输入 1 个整数 m (1 <= m <= n),代表幸运用户的人数
最后 1 行输入 m 个用空格隔开的整数,表示幸运用户的编号
用户按照题目中输入顺序从 1 到 n 编号。
Output
对于每组数据,输出 m 行,为幸运用户名单,每个用户信息占一行(按照给出的幸运用户编号顺序输出)。
Sample Input
3
Alice alice@hotmail.com
bLue tbdblue@gmail.com
cyk 9#409
2
3 1
Sample Output
cyk 9#409
Alice alice@hotmail.com
Hint
Source
【2016级《程序设计基础(B)II》期末上机考试-第一场】bLue
#include <stdio.h>
#include <stdlib.h>
struct node
{
char name[13],tel[34];
int num;
}a[101];
int main()
{
int n,i,m,p;
while(~scanf("%d",&n))
{
for(i=1;i<=n;i++)
{
scanf("%s%s",a[i].name,a[i].tel);
a[i].num=i;
}
scanf("%d",&m);
while(m--)
{
scanf("%d",&p);
for(i=1;i<=n;i++)
{
if(i==p)
{
printf("%s %s\n",a[i].name,a[i].tel);
break;
}
}
}
}
return 0;
}