Posts

Showing posts from August, 2021

Solution of 'Variable Sized Arrays' (HackerRank)

  Hi guys, here's my solution of the question-'Variable Sized Arrays' from HackerRank. Again, if you guys have any doubts regarding my code, any suggestions for my code or blog, do comment below. TY and Happy Coding! #include   <bits/stdc++.h> using   namespace   std ; int   main () {      int   n , q ;      cin >> n >> q ;      vector < int >  v [ n ];      for ( int   i = 0 ; i < n ; i ++){          int   Q ;          cin >> Q ;          for ( int   j = 0 ; j < Q ; j ++){              int   x ;              cin >> x ;              v [ i ]. push_back ( x );         }     }      while ( q --){          int   i , t ;          cin >> i >> t ;          auto   itr = v [ i ]. begin () + t ;          cout << * itr << ' \n ' ;     } }

Solution of 'FIGUREFUL' (SPOJ)

  Hey everyone! Here's my solution of the question- 'FIGUREFUL' from SPOJ. Do comment your suggestions for my blogs and code. TY and Happy coding! question link: https://www.spoj.com/problems/ACMCEG2B/ #include   <bits/stdc++.h> using   namespace   std ; int   main () {      map < pair < int , int >,  string >  code ;      int   n , q ;      cin >> n ;      for ( int   i = 0 ; i < n ; i ++){          int   x , y ;          string   s ;          cin >> x >> y >> s ;          code [ { x , y } ] = s ;     }      cin >> q ;      string   name [ q ];      for ( int   i = 0 ; i < q ; i ++){          int   x , y ;          cin >> x >> y ;          name [ i ] = code [ { x , y } ] ;     }      for ( int   i = 0 ; i < q ; i ++){          cout << name [ i ] << ' \n ' ;     }      return   0 ; }

Solution of 'Less or Equal' (Codeforces)

  Hey guys! Here's my solution of question-'Less or Equal' from Codeforces. I am looking forward to your suggestions for my code or blog. So do comment. TY and Happy coding! question link: https://codeforces.com/contest/977/problem/C #include   <bits/stdc++.h> #define   pair   < int,int >  pp using   namespace   std ; int   main () {      int   n , k ;      cin >> n >> k ;      vector < int >  vec ;      for ( int   i = 0 ; i < n ; i ++){          int   x ;          cin >> x ;          vec . push_back ( x );     }      sort ( vec . begin (), vec . end ());      if (( k != 0 )&&( vec [ k - 1 ] != vec [ k ] )) { cout << vec [ k - 1 ] ;}      else   if (( k == 0 )&& vec [ k ] != 1 ){ cout << vec [ k ] - 1 ;}      else {          cout << - 1 ;     } }

Solution of 'Three Friends' (Codeforces)

 Hello everyone! Here's my solution of the question-'Three Friends' from Codeforces. Any suggestion for me is highly appreciated. Happy Coding! question link: https://codeforces.com/problemset/problem/1272/A #include   <bits/stdc++.h> #define   long  long long int using   namespace   std ; int   main () {      int   q ;      cin >> q ;      int   d [ q ];      for ( int   m = 0 ; m < q ; m ++){          int   a , b , c , min = 1999999999 ;          cin >> a >> b >> c ;          int   a1 [ 3 ]={ a + 1 , a , a - 1 };          int   b1 [ 3 ]={ b + 1 , b , b - 1 };          int   c1 [ 3 ]={ c + 1 , c , c - 1 };          for ( int   i = 0 ; i < 3 ; i ++){              for ( int   j = 0 ; j < 3 ; j ++){                  for ( int   k = 0 ; k < 3 ; k ++){                      int   s = abs ( a1 [ i ]- b1 [ j ])+ abs ( b1 [ j ]- c1 [ k ])+ abs ( c1 [ k ]- a1 [ i ]);                      if ( min > s ) { min = s ;}                 }      

Solution of 'Choose Two Numbers' (Codeforces)

Hola amigos! Here's my solution of the question- 'Choose Two Numbers' from Codeforces. If you guys have any suggestions for my code or blog or anything, do comment. TY and Happy Coding! question link: https://codeforces.com/problemset/problem/1206/A #include   <bits/stdc++.h> using   namespace   std ; int   main () {      int   n , m , f = 0 ;      cin >> n ;      vector < int >  a ;      for ( int   i = 0 ; i < n ; i ++){          int   x ;          cin >> x ;          a . push_back ( x );     }      cin >> m ;      vector < int >  b ;      for ( int   i = 0 ; i < m ; i ++){          int   x ;          cin >> x ;          b . push_back ( x );     }      vector < int >  c ;      for ( int   i = 0 ; i < n ; i ++){          for ( int   j = 0 ; j < m ; j ++){              int   h = a [ i ] + b [ j ] ;              if ( find ( a . begin (), a . end (), h ) == a . end ()&& find ( b . begin (), b . end (), h ) ==

Solution of 'Tom Riddle's Diary' (Codeforces)

  Hey everyone! Here's my solution of the question- Tom Riddle's Diary from Codeforces. If you guys have any suggestion do comment. T.Y. and Happy coding. question link: https://codeforces.com/contest/855/problem/A #include   <bits/stdc++.h> using   namespace   std ;   int   main () {      vector < string > v ;      int   n ;      cin >> n ;      string   a [ n ];      for ( int   i = 0 ; i < n ; i ++){          string   p ;          cin >> p ;          v . push_back ( p );          int   h = count ( v . begin (),  v . end (), p );          if ( h == 1 )  a [ i ] = "NO" ;          else   a [ i ] = "YES" ;     }      for ( int   j = 0 ; j < n ; j ++)  cout << a [ j ] << ' \n ' ;      return   0 ; }

Solution of 'Maps-STL' (Hackerrank)

So, here's my solution of the question- Maps-STL of Hackerrank. If you guys have any suggestions, do comment. Thank you and Happy coding. link: https://www.hackerrank.com/challenges/cpp-maps/problem #include   <cstdio>   #include   <cmath> #include   <vector> #include   <iostream> #include   <set> #include   <map> #include   <algorithm> using   namespace   std ; int   main () {      int   q ;      cin >> q ;      int   a [ q ];      map < string , int >  mark ;      for ( int   i = 0 ; i < q ; i ++){          cin >> a [ i ];          if ( a [ i ]== 1 ){              string   p ;              int   k ;              cin >> p >> k ;              mark [ p ] += k ;         }          else   if ( a [ i ]== 2 ){              string   p ;              cin >> p ;              mark [ p ] = 0 ;         }          else   if ( a [ i ]== 3 ){              string   p ;              cin >> p ;              cout