Posts

SUM OF ALL SUBARRAY

  #include <iostream> using namespace std ; int main () {     int n ;     cin >> n ;     int arr [ n ];     for ( int i = 0 ; i < n ; i ++)     {         cin >> arr [ i ];     }     int sum = 0 ;     for ( int i = 0 ; i < n ; i ++)     {         sum = 0 ;         for ( int j = i ; j < n ; j ++)         {             sum += arr [ j ];             cout << sum << " " ;         }         cout << endl ;     } }

LONGEST ARITHMETIC SUBARRAY

  #include <iostream> using namespace std ; int main () {     int n;     cin >> n;     int a [n];     for ( int i = 0 ; i < n; i++)     {         cin >> a [i];     }     int d = a [ 1 ] - a [ 0 ];     int ans = 2 ;     int curr = 2 ;     for ( int i = 2 ; i < n; i++)     {         if ( a [i] - a [i - 1 ] == d)             curr++;         else         {             d = a [i] - a [i - 1 ];             curr = 2 ;         }         ans = max (ans, curr);     }     cout << ans; }

RECORD BREAKING DAY

  #include <iostream> using namespace std ; int main () {     int n ;     cin >> n ;     int a [ n + 1 ];     for ( int i = 0 ; i < n ; i ++)     {         cin >> a [ i ];     }     a [ n ] = - 1 ;     if ( n == 1 )     {         cout << "1" << endl ;     }     int ans = 0 ;     int mx = - 1 ;     for ( int i = 0 ; i < n ; i ++)     {         if ( a [ i ] > mx && a [ i ] > a [ i + 1 ])             ans ++;         mx = max ( mx , a [ i ]);     }     cout << ans << endl ; }

FIRST REPEATING ELEMENT

  #include <bits/stdc++.h> using namespace std ; int main () {     int n;     cin >> n;     int arr [n];     for ( int i = 0 ; i < n; i++)     {         cin >> arr [i];     }     const int N = 1e5 ;     int idx [N];     for ( int i = 0 ; i < N; i++)     {         idx [i] = - 1 ;     }     int minidx = INT16_MAX;     for ( int i = 0 ; i < n; i++)     {         if ( idx [ arr [i]] != - 1 )         {             minidx = min (minidx, idx [ arr [i]]);         }         else         {             idx [ arr [i]] = i + 1 ;         }     }             co...

Day vs Dates

  #include <iostream> using namespace std ; int main () {     int d1, m1, y1, d2, m2, y2, days = 0 ;     cout << "Enter the date in the format DD MM YYYY to DD MM YYYY :" ;     cin >> d1 >> m1 >> y1;     cout << " -> " ;     cin >> d2 >> m2 >> y2;     int arr1[] = { 0 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };     // int arr2[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};     int year = 0 , month = 0 ;     if ((y2 + m2) > (y1 + m1))     {         year = (y2 - y1);     }     else     {         year = 0 ;     }     if ((m2 - m1) != 0 )     {         days = arr1 [m1] - d1 + d2;     }     else     {         days = d2 - d1; ...

Integer To Roman Converter Upto 10,000.

  #include <iostream> using namespace std ; int main () {     string arr1 []={ " " , "I" , "II" , "III" , "IV" , "V" , "VI" , "VII" , "VIII" , "IX" };     string arr2 []={ " " , "X" , "XX" , "XXX" , "XL" , "L" , "LX" , "LXX" , "LXXX" , "XC" , "C" };     string arr3 []={ " " , "C" , "CC" , "CCC" , "CD" , "D" , "DC" , "DCC" , "DCCC" , "CM" , "M" };     string arr4 []={ " " , "M" , "MM" , "MMM" , "IV̅" , "V̅" , "V̅M" , "V̅MM" , "V̅MMM" , "V̅MMMM" , "X̅" };     int n ;     cin >> n ;     cout << arr4 [ n / 1000 ] << arr3 [( n % 1000 )/ ...

Amount Vs Word

  #include <iostream> #include <cstring> using namespace std ; void Amount_Word ( int amt ) {     string arr1 [] = { "zero" , "one" , "two" , "three" , "four" , "five" , "six" , "seven" , "eight" , "nine" , "ten" , "eleveen" , "twelve" , "thirteen" , "fourteen" , "fifteen" , "sixteen" , "seventeen" , "eighteen" , "nineteen" , "twenty" };     string arr2 [] = { "ten" , "twenty" , "thirty" , "fourty" , "fifty" , "sixty" , "seventy" , "eighty" , "ninety" };     // For Amount less than 100     if ( amt < 100 )     {         if ( amt <= 20 )         {             cout << arr1 [ amt ] << " " ;         }         else if ( amt >= 21 &...