Q.MANIKARAN MARKETING.?
#include<iostream>
using namespace std;
void findClosest(int A[], int B[], int C[], int p, int q, int r)
{
int diff = 1000;
int res_i =0, res_j = 0, res_k = 0;
int i=0,j=0,k=0;
while (i < p && j < q && k < r)
{
int minimum = min(A[i], min(B[j], C[k]));
int maximum = max(A[i], max(B[j], C[k]));
if (maximum-minimum < diff)
{
res_i = i, res_j = j, res_k = k;
diff = maximum - minimum;
}
if (diff == 0) break;
if (A[i] == minimum) i++;
else if (B[j] == minimum) j++;
else k++;
}
cout << A[res_i] << " " << B[res_j] << " " << C[res_k];
}
int main()
{
int A[10] ;
int B[10] ;
int C[10] ;
int p;
int q;
int r,i;
scanf("%d",&p);
for(i=0;i<p;i++) { scanf("%d",&A[i]) ; }
scanf("%d",&q);
for(i=0;i<q;i++) { scanf("%d",&B[i]) ; }
scanf("%d",&r);
for(i=0;i<r;i++) { scanf("%d",&C[i]) ; }
findClosest(A, B, C, p, q, r);
return 0;
}
Q2.ABHIMANYU QUESTION?.
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;cin >> n;
int a[n];
map<int,int> mp;
for(int i=0;i<n;i++){
cin >> a[i];
mp[a[i]]++;
}
int mx = INT_MIN;int ans= 0;
for(auto i : mp){
if(i.second > mx){
ans = i.first;
mx =i.second;
}
}
cout << ans << " " << mx;
return 0;
}
Q3.THE CLASS TEACHER ANNOUNCES RANKS?
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;cin >> n;
int a[n];
map<int,int> mp;
for(int i=0;i<n;i++){
cin >> a[i];
mp[a[i]]++;
}
for(auto i : mp){
if(i.second > 1)
cout << i.first << "-" << i.second << endl;
}
return 0;
}
Q4.The class teacher has informed the students to stand in a particular order by
heightwise for the independence day event?
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;cin >>n;
int a[n];
map<int,int> mp;
for(int i=0;i<n;i++){
cin >> a[i];
mp[a[i]]++;
}
for(auto i : mp){
if(i.second == 1){
cout << i.first;
break;
}
}
return 0;
}
Q5.POST MAN?
#include <iostream>
using namespace std;
int main()
{
int a[10],i,j,n,ev=0,od=0;
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n;i++)
{
if(a[i]%2==0)
ev=ev+1;
else
od=od+1;
}
cout<<"Right-"<<ev<<endl;
cout<<"Left-"<<od;
return 0;
}
Q6.suresh is conducting an entertiment even for students?
#include <iostream>
using namespace std;
void printSums(int N){
int initial = 1;
while(initial < (N+1)/2){
int sum=0;
for(int i=initial; i<=(N+1)/2; i++){
sum = sum + i;
if(sum == N){
for(int j=initial; j<=i; j++){
cout << j << " ";
}
cout << endl;
break;
}
}
initial++;
sum = 0;
}
}
int main() {
int n;
cin >> n;
printSums(n);
return 0;
}
Q7.DRAGON?
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,d;
cin>>a>>b>>c>>d;
while((b!=d) && b< 100000)
{
(b<d)? b+=a : d+=c; //39 52 88 78 1222
}
cout<<(b==d?b:-1);
return 0;
}
Q9.arrayAof non-negative integers of sizem is given. ?
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;cin >> n;
int a[n],b[n],c[n];
vector<int> v,v1;
for(int i=0;i<n;i++){
cin >> a[i];
b[i] = a[i];
c[i] = i;
}
sort(a,a+n);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(a[i]==b[j]){
cout<<c[j]<<" ";
}
}
}
return 0;
}
Q10.Given the array of n elements and sort it using insertion sort. The first line
of the input contains the no of elements and the second line contains the numbers
to be sorted. print the array after each iteration of the insertion
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;cin >> n;
int a[n];
for(int i=0;i<n;i++){
cin >> a[i];
}
for(int i=1;i<n;i++){
int j=i;
int value = a[i];
while(j>=1 && a[j-1] > value){
a[j] = a[j-1];
j--;
}
a[j] = value;
for(int k=0;k<n;k++)
cout << a[k] << " " ;
cout << endl;
}
return 0;
}
Q11.UDAY WALA?
#include<bits/stdc++.h>
using namespace std;
void findTriplets(int arr[], int n)
{
bool found = true;
for (int i=0; i<n-2; i++)
{
for (int j=i+1; j<n-1; j++)
{
for (int k=j+1; k<n; k++)
{
if (arr[i]+arr[j]+arr[k] == 0)
{
cout << arr[i] << " "
<< arr[j] << " "
<< arr[k] <<endl;
found = true;
}
}
}
}
if (found == false)
cout << " not exist "<<endl;
int main()
{
int arr[] = {0, -1, 2, -3, 1};
int n = sizeof(arr)/sizeof(arr[0]);
findTriplets(arr, n);
return 0;
}
Q12.Given an array of integers, sort the array according to frequency of elements.
For example, if the input array is {2, 3, 2, 4, 5, 12, 2, 3, 3, 3, 12}, then modify
the array to {3, 3, 3, 3, 2, 2, 2, 12, 12, 4, 5}.
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define cyes cout << "YES" << endl
#define cno cout << "NO" << endl
#define f(i, a, n) for(int i = a; i < n; i++)
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mod 1000000007
int gcd(int a, int b) { if (!b) return a; return gcd(b, a % b); }
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
using namespace std;
bool sortbysecond(const pair<int,int>&i,const pair<int,int>&j){
if(i.second == j.second)
return i.first < j.first;
return i.second > j.second;
}
int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int t;cin >> t;
while(t--){
int n;cin>>n;
int a[n];
map<int,int> mp;
for(int i=0;i<n;i++){
cin >> a[i];
mp[a[i]]++;
}
vector<pair<int,int>> v;
for(auto i : mp){
v.push_back(make_pair(i.first,i.second));
}
sort(v.begin(), v.end(),sortbysecond);
for(auto i : v){
int k = i.second;
while(k--){
cout << i.first << " ";
}
}
cout << endl;
}
}
Q14.FARMER?
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;cin >> n;
int a[n];
vector<int> v,v1;
for(int i=0;i<n;i++){
cin >> a[i];
}
sort(a,a+n);
for(int i=0;i<n;i++){
if(a[i]%2==0)
v.push_back(a[i]);
else
v1.push_back(a[i]);
}
for(auto i : v){
cout << i << " ";
}
cout << endl;
for(auto i : v1){
cout << i << " ";
}
return 0;
}
Q16.RAM MADAN SONU?
#include <bits/stdc++.h>
using namespace std;
int main(){
string a[3];
for(int i=0;i<3;i++){
cin >> a[i];
}
string s;cin >> s;
int k=0;
for(int i=0;i<3;i++){
if(s==a[i]){
k=1;break;
}
}
if(k==1)
cout << "Yes";
else
cout << "No";
return 0;
}
Q17.