In this HackerEarth Split houses problem solution, you are given an array A of size N that contains integers. Here, N is an even number. You are required to perform the following operations:
- Divide the array of numbers in two equal halves
- Note: Here, two equal parts of a test case are created by dividing the array into two equal parts.
- Take the first digit of the numbers that are available in the first half of the array (first 50% of the test case)
- Take the last digit of the numbers that are available in the second half of the array (second 50% of the test case)
- Generate a number by using the digits that have been selected in the above steps
Your task is to determine whether the newly-generated number is divisible by 11.
HackerEarth Divisible problem solution.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007ll
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define db(x) cout << #x << " = " << x << '\n'
int main(int argc, char const *argv[]) {
return 0;
}
second solution
#include<bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define vll vector<ll>
#define llin(a) ll a; cin>>a;
#define llin2(a,b) ll a,b; cin>>a>>b;
#define llin3(a,b,c) ll a,b,c; cin>>a>>b>>c;
#define fulll(v) v.begin(),v.end()
#define vecin(n, v) for(ll i=0; i<n;i++) cin>>v[i];
#define vecout(n, v) for(ll i=0; i<n;i++) cout<<v[i]<<" "; cout<<endl;
#define rep(i, s, n) for(ll i=(ll)s;i<(ll)n;i++)
#define rrep(i, s, n) for(ll i=(ll)s;i>=(ll)n;i--)
#define pb push_back
#define mkp make_pair
#define endl "\n"
#define test cout<<"test line"<<endl;
#define swapper void swap(ll *a, ll *b){ll t=*a;*a=*b;*b=t;}
#define pll pair<ll,ll>
#define vpll vector<pll >
#define mod 1000000007
#define INF 0x3f3f3f3f
#define MAX 100005
using namespace std;
int main(){
llin(n);
assert(n>=1 && n<=100000);
ll se=0, so=0;
rep(i,0,n){
string s;
cin>>s;
stringstream check(s);
ll val;
check>>val;
assert(val>=1 && val<=100000);
if(i<n/2)
i&1?so+=s[0]-'0':se+=s[0]-'0';
else
i&1?so+=s.back()-'0':se+=s.back()-'0';
}
if(se==so)
cout<<"OUI";
else
cout<<"NON";
return 0;
}
0 Comments