Posts

Showing posts from August, 2023

AtCoder Roulette

  #include < bits / stdc ++. h > using namespace std ;   const int high = 205 ;   int ar [ high ][ high ], ans [ high ], allC [ high ], mp [ high ][ high ];   struct data { int indx ; int c ; } sarr [ high ];   void sol ( int N ) { int C , clen = 0 ; for ( int i = 0 ; i < N ; i ++) { cin >> C ; allC [ clen ++] = C ; for ( int j = 0 ; j < C ; j ++) { cin >> ar [ i ][ j ]; } } int X , minC = 37 , slen = 0 ; cin >> X ; for ( int i = 0 ; i < N ; i ++) { for ( int j = 0 ; j < allC [ i ]; j ++) { if ( ar [ i ][ j ] == X ) { if ( mp [ i ][ j ] == 0 ) { mp [ i ][ j ] = 1 ; sarr [ slen ]. indx = i + 1 ; sarr [ slen ++]. c = allC [ i ]; if ( minC > allC [ i ]) { minC = allC [ i ];

AtCoder 3.14

#include < bits / stdc ++. h > using namespace std ;   void sol ( int N , string pi ) { int len = pi . length (); N = 2 + N ; for ( int i = 0 ; i < N ; i ++) { cout << pi [ i ]; } }   int main () { string pi = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679" ; int N ; cin >> N ; sol ( N , pi ); return 0 ; }

AtCode A - To Be Saikyo

 Problem Description Link:  https://atcoder.jp/contests/abc313/tasks/abc313_a Accepted Solution #include <bits/stdc++.h> using namespace std ; int sol ( int N ) {     int i , a , mx = - 1 , first = 0 , cnt = 0 ;     cin >> first ;     mx = max ( mx , first );     for ( i = 1 ; i < N ; i ++ ) {         cin >> a ;         if ( a == first ) {             cnt += 1 ;         }         mx = max ( mx , a );     }         int x = mx - first ;     if ( cnt == 0 && mx != first ) {         return x + 1 ;     }     else if ( cnt == 0 && mx == first ) {         return 0 ;     }     else if ( cnt >= 1 && cnt != ( N - 1 )) {         return x + 1 ;     }     else {         return x + 1 ;     } } int main () {     int N ;     cin >> N ;     int ans = sol ( N );     cout << ans << " \n " ;     return 0 ; }

LeetCode Roman to Integer

 Problem Description Link:  https://leetcode.com/problems/roman-to-integer/ Accepted Solution /* The solution to the problem is straightforward. You have to find the exceptional numbers, such as 4, 9, 40, 90, 400, and 900, carefully and do simply for the rest. */ class Solution { public:     int getNum ( char ch ) {     if (ch == 'I' )     {         return 1 ;     }     else if (ch == 'V' )     {         return 5 ;     }     else if (ch == 'X' )     {         return 10 ;     }     else if (ch == 'L' )     {         return 50 ;     }     else if (ch == 'C' )     {         return 100 ;     }     else if (ch == 'D' )     {         return 500 ;     }     else if (ch == 'M' )     {         return 1000 ;     }     return 0 ;     }     int romanToInt ( string s ) {                 string roman = s;         int i= 0 , len = roman . length (), num= 0 ;     for (i= 1 ; i<len; i++)     {         //cout << getNum

LeetCode Reverse Integer

 Problem Description:  https://leetcode.com/problems/reverse-integer/description/ Accepted Solution /* I have learned some crucial things during solving the problem. For example, if you want to check integer overflows for several operations, you have to manage the following conditions: int a = <something>;  int x = <something>; if (x < 0 && a > INT_MAX + x) // a - x would overflow   // `a - x` would overflow if (x > 0 && a < INT_MIN + x) // a - x would underflow if (a == -1 && x == INT_MIN) // a * x can overflow if (x == -1 && a == INT_MIN) // a * x (or a / x) can overflow if (x != 0 && a > INT_MAX / x) // a * x would overflow if (x != 0 && a < INT_MIN / x) // a * x would underflow Hence, check the appropriate conditions in perfect positions at your code. Also, keep your attention when you are dealing with a negative number. Moreover, a negative number is unsuitable for direct calculation or div