PTA:Pair Up for the Autumn Outing

The students are so excited—they can finally go on an autumn outing! The teacher says that it's a bit dangerous to go alone, so let's pair up and travel together. The pairing rule is as follows: the first person in line pairs up with the last person, the second person pairs up with the second-to-last person, and so on, forming pairs of two. Now, let's quickly organize! As soon as the teacher finishes speaking, the students pair up swiftly, ready to set off!

Input Format:

The first line is an integer n, representing the number of students. (2<=n<=50,and n is even).
The second line contains n integers representing the student numbers, separated by spaces.

Output Format:

There are n/2 lines, each containing two integers representing the paired student numbers, separated by a space.

Sample Input:

6
5 6 4 12 3 2

Sample Output:

5 2
6 3
4 12

代码如下:

#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int j=0;j<n/2;j++)
    {
        cout<<a[j]<<" "<<a[n-j-1]<<endl;
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值