Problem1071--数组练习1

1071: 数组练习1

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 40  Solved: 0
[Submit] [Status] [Web Board] [Creator:]

Description

给出一条长度为n的数组,接下来有m次提问,每次提问给出一个数x(x<=n),输出第x个数。

Input

第一行两个数n,m(10<=n,m<=100),分别表示数组长度和提问个数。
第二行有n个数,保证每个数均为小于10000的正整数。
接下来m行,每行一个数x。

Output

共m行,每行一个正整数。

Sample Input

5 2
1 3 5 4 2
1
4

Sample Output

1
4

HINT

#include <iostream>
using namespace std;
int main()
{
  int a[101],i,n,m,x;
  cin>>n>>m;
  for(i=0;i<n;i++)
    cin>>a[i];
    
  while(m>0)
  {
  cin>>x;
  printf("%d\n",a[x-1]);
  m--;
  }
}

Source/Category


[Submit] [Status]