Posts

Showing posts with the label Two Strings

HackerEarth's basic programming solutions( IT’S MAGIC!, Two Strings, Print the Numbers ) :

Problem 15: IT’S MAGIC! Solution: (in c++) ( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder) #include< bits/stdc++.h > using namespace std ; int main () { long long n , min = 10000000000 , i , sum = 0 , index=- 1 , j ; cin >> n ; long long a [ n ]; for ( i = 0 ; i < n ; i ++) {     cin >> a [ i ];     sum += a [ i ]; // sum now stores the sum of array } for ( j = 0 ; j < n ; j ++) {      if (( sum - a [ j ])% 7 == 0 && a [ j ]< min )      {         min = a [ j ];         index = j ;      } } cout << index ; } In this problem , simply we have to remove the smallest multiple of 7 from the array. Read the above code and try it with the example given below to understand. input                             output 5 14 7 8 2 4 1       Problem 16: Two Strings Solution: (in c++) ( please guys before moving to the solution try it yourself