Posts

Showing posts from July, 2021

Unique Birthday Gift - INFOSYS - SAMPLE QUESTION - 2

Image
 Unique Birthday Gift - INFOSYS - SAMPLE QUESTION - 2 (SOLUTION ) #include <iostream> #include <vector> #include <utility> using namespace std ; int main () { int i ; int c = 0 ; int n , k ; cin >> n ; cin >> k ; vector < pair < int , int >>v ; int j ; if ( n == 1 || k == 1 ) { int temp ; temp = n>k?n:k; cout << temp<< endl ; } else { for (i = 1 ; i <= k+ 1 ; i++) { for (j = 1 ; j <= n; j++) { pair < int , int > p = make_pair (i, j); v. push_back (p); } } for ( auto it : v) { if ( it. second % it. first == 0 ) { c++ ; } } } if (c) { cout << c << endl ; } return 0 ; }

Infosys - Monster RPG GAME Sample Question Solution

Image
Monster RPG GAME - Solution #Infosys SOLUTION    #include <iostream> #include <map> #include <algorithm> using namespace std ; void game ( map < int , int > & g , int energy ) { int c = 0 ; for ( auto & itr : g ) { if ( energy >= itr. first ) { c++; energy = energy + itr. second ; } else { continue ; } } cout << c << endl ; } void mapping ( int p [], int b [], int n , int energy ) { int count ; map < int , int > m ; // mapping the key value pair from the array int i ; for ( i = 0 ; i < n ; i++) { m. insert ({ p [i], b [i]}); } for ( auto & itr : m) { cout << itr. first << " " << itr. second << endl ; } game (m, energy ) ; } int main () { int n ; cin >> n ; int i ; int p[n] ; int b[n] ; int e ; cin >> e ; // energy i have for (i = 0 ; i < n ; i++ ) { cin >> p[i] ...