Tuesday, April 28, 2020

492A. Vanya and Cubes

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int n;
  6. int s=0;
  7. int sum=0;
  8. int cube=0;
  9. cin>>n;
  10. for(int j=1;j<=n;j++)
  11. {
  12. sum =sum +j;
  13. s=sum+s;
  14. if(s>n) break;
  15. cube++;
  16. }
  17. cout<<cube;
  18. }

Monday, April 27, 2020

749A. Bachgold Problem Solution

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int n;
  6. int q=2;
  7. int c=0;
  8. cin>>n;
  9. if(n%2==0)
  10. {
  11. int p=n/2;
  12. cout<<p<<endl;
  13. for(int i=0;i<p;i++)
  14. cout<<2<<" ";
  15. }
  16.  
  17. else{
  18.  
  19. q=n/2-1;
  20. cout<<q+1<<endl;
  21. for(int j=0;j<q;j++)
  22. cout<<2<<" ";
  23.  
  24.  
  25. }
  26. if(n%2!=0)cout<<3;
  27.  
  28. return 0;
  29. }
  30.  

118A. String Task Solution

  1. #include<iostream>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. int main(){
  5. int i;
  6. char ch[100];
  7. cin>>ch;
  8.  
  9.  
  10. int size=std::strlen(ch);
  11.  
  12. ////cout<<size<<endl;
  13.  
  14. for(i=0;i<size;i++)
  15. {
  16. if(ch[i]=='a' ||ch[i]=='e' ||ch[i]=='i' ||ch[i]=='o' ||ch[i]=='u' ||ch[i]=='y' ||ch[i]=='A' ||ch[i]=='E' ||ch[i]=='I' ||ch[i]=='O' ||ch[i]=='U' ||ch[i]=='Y')
  17. continue;
  18. cout<<".";
  19. if(ch[i]>='A' && ch[i]<='Z')
  20. cout<<(char)tolower(ch[i]);
  21. else cout<<ch[i];
  22.  
  23.  
  24.  
  25. }
  26.  
  27. return 0;
  28.  
  29. }

71A. Way Too Long Words

  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4. int main()
  5. {
  6. int t;
  7. string str;
  8. int i,ln;
  9. cin>>t;
  10. for(i=0;i<t;i++)
  11. {cin>>str;
  12. ln=str.length();
  13. if(ln>10)
  14. {cout<<str.at(0)<<ln-2<<str.at(ln-1)<<endl;
  15. }
  16. else cout<<str<<endl;
  17. }
  18. return 0;

Sunday, April 26, 2020

263A A Beautiful Matrix

#include<iostream>
using namespace std;
int main(){
int arr[5][5];
int j,i=0;
int loc;
for(i=0;i< 5;i++){
 for(j=0;j<5;j++)
cin>>arr[i][j];}

for(i=0;i< 5;i++){
 for(j=0;j<5;j++)
 if(arr[i][j]==1) cout<<abs(2-i)+abs(2-j);
 }
}

1A. Theatre Square solution


  1. #include
    <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. long double a, n, m, temp;
  8.  
  9. cout.precision(22);
  10. cin >> n >> m >>a;
  11. if(m < n)
  12. {
  13. temp = m;
  14. m = n;
  15. n = temp;
  16. }
  17.  
  18. if(a >= m)
  19. {
  20. cout << ceil(n/a) << endl;
  21. }
  22. else
  23. {
  24. cout << ceil(m/a)*ceil(n/a) << endl;
  25. }
  26. return 0;
  27. }

4A Watermelon solution

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int w;
  6. cin>>w;
  7. if(w!=2 && w%2==0)
  8. cout<<"YES"<<endl;
  9. else cout<<"NO"<<endl;
  10. return 0;
  11. }

Saturday, April 25, 2020

703A. Mishka and Game Solution Codeoforces

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {int cm=0,cn=0;
  5. int n=0,m=0,c=0;
  6. int sum=0,sumM=0,sumN=0;
  7. cin>>n;///round
  8. int i;
  9. for(i=0;i<n;i++){
  10. cin>>m>>c;
  11.  
  12. if(m==c) continue;
  13. if(m>c) cm++;
  14. if(m<c) cn++;
  15. }
  16. //cout<<cm<<" " <<cn;
  17. if(cm==cn)cout<<"Friendship is magic!^^\n";
  18. if(cm>cn)cout<<"Mishka\n";
  19. if(cm<cn) cout<<"Chris\n";
  20. return 0;
  21. }

1097A. Gennady and a Card Game solution


  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. string table;
  6. string hand,s="";
  7. int i;bool yes=false;
  8. cin>>table;
  9. for(int j=0;j<5;j++)
  10. {
  11. cin>>hand;
  12. if(hand[0]==table[0] or hand[1]==table[1] or hand[1]==table[0] or hand[0]==table[1])
  13. {yes=1;
  14.  
  15. break;}
  16.  
  17. }
  18. if(yes==1)cout<<"YES";
  19. else cout<<"NO";
  20. return 0;
  21. }

723A. The New Year: Meeting Friends Solution

  1. #include<iostream>
  2. #include<algorithm>
  3. using namespace std;
  4. int main()
  5. {
  6. int arr[3];
  7. cin>>arr[0]>>arr[1]>>arr[2];
  8. sort(arr,arr+3);
  9. cout<<arr[1]-arr[0]+abs(arr[1]-arr[2]);
  10. }

509A Maximum in Table

  1. #include <iostream>
  2. using namespace std;
  3. int a, arr[10][10];
  4. int main() {
  5. cin >> a;
  6. for (int i = 0; i < a; i++) {
  7. for (int j = 0; j < a; j++) {
  8. if (i == 0) {
  9. arr[i][j] = 1;
  10. } else if (j == 0) {
  11. arr[i][j] = 1;
  12. } else {
  13. arr[i][j] = arr[i - 1][j] + arr[i][j - 1];
  14.  
  15. }
  16. }
  17. }
  18. cout << arr[a - 1][a - 1];
  19. }

1343 A candies Solution

  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. long n,k=1,x,i;
  6. int t;cin>>t;
  7. while(t--){
  8. cin>>n;
  9. for(i=0;i<=n;i++)
  10. {k=1+2*k;
  11. if(n%k==0){ x=n/k;cout<<x<<endl;k=1;break;}
  12.  
  13.  
  14. }
  15.  
  16. }
  17.  
  18. }

935 A. Fafa and his Company solution


  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int n;cin>>n;
  6. int ans =0,em=0,lr=0,i;
  7. for(i=1;i<n;i++)
  8. {lr=i;
  9. em= n-i;
  10. if(lr+em==n and em%lr==0) ans++;
  11. }
  12.  
  13. cout<<ans;
  14. return 0; }

490 A. Team Olympiad Solution

#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int arr[n];
int t1=0,t2=0,t3=0;
int ans= 0;
long p1[10000],p2[10000],p3[10000];
for(int j ;j<n;j++)
cin>>arr[j];
int i;
int a=0,b=0,c=0;
for(i=0;i<n;i++)
{

if(arr[i]==1 )
{t1++;
p1[a]=i;a++;
}


else if(arr[i]==2 ){
t2++;
p2[b]=i;b++;}
else if(arr[i]==3  ){
t3++;
p3[c]=i;
c++;}
ans = min(t1,min(t2,t3));
}
cout<<ans<<endl;;
t1=0,t2=0,t3=0;
int k=0;
for(i=0;i<n;i++)
{
if(ans>=1) cout<<p1[i]+1<<" "<<p2[i]+1<<" " <<p3[i]+1<<" "<<endl;
 k++;

if(k==ans)break;
}



return 0;
}

Aptitude test assistant programmer 2018

 #include <stdio.h> #include <stdlib.h> int main() { char str[100]; int i; int space=0;     printf("Enter a string\n")...