Codeforces 1339B. Sorted Adjacent Differences Solution
Solution in C++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include<iostream>
#include <algorithm>
#define ef(i,a,b) for(int i=a; i<=b; i++)
#define enf(i,b,a) for(int i=b; i>=a; i--)
using namespace std;
const int M = 100000 + 9;
int main()
{
int t,ar[M],n,i,j;
while(cin>>t)
{
while(t--)
{
cin>>n;
ef(i,1,n)
cin>>ar[i];
sort(ar+1,ar+1+n);
if(n%2==1)
cout<<ar[(n+1)/2]<<" ";
enf(i,n/2,1)
cout<<ar[n-i+1]<<" "<<ar[i]<<" ";
cout<<endl;
}
}
}
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include<iostream>
#include <algorithm>
#define ef(i,a,b) for(int i=a; i<=b; i++)
#define enf(i,b,a) for(int i=b; i>=a; i--)
using namespace std;
const int M = 100000 + 9;
int main()
{
int t,ar[M],n,i,j;
while(cin>>t)
{
while(t--)
{
cin>>n;
ef(i,1,n)
cin>>ar[i];
sort(ar+1,ar+1+n);
if(n%2==1)
cout<<ar[(n+1)/2]<<" ";
enf(i,n/2,1)
cout<<ar[n-i+1]<<" "<<ar[i]<<" ";
cout<<endl;
}
}
}
can you please explain statement cin>>t??
ReplyDeletecin>>t it use for get input from keyboard.here is 't' is test case number
Delete