Posts

ACM ICPC Team

 Question :- https://www.hackerrank.com/challenges/acm-icpc-team/problem Solution in C language :- #include< stdio.h > #include< string.h > int   main (){      int   n , m ;      scanf ( "%d%d" ,& n ,& m );      char   str [ n ][ m ];      int   i , j ;      for ( i = 0 ; i < n ; i ++){          scanf ( "%s" , str [ i ]);      }      int   c = 0 , k , cm = 0 , z = 1 ;      for ( i = 0 ; i < n ; i ++){          for ( j = i + 1 ; j < n ; j ++){              c = 0 ;              for ( k = 0 ; k < m ; k ++){                  if ( str [ i ][ k ]== '1'   ||   str [ j ][ k ]== '1' )                      c ++;              }              if ( cm < c ){                  cm = c ;                  z = 1 ;              }              else   if ( cm == c )                  z ++;          }      }      printf ( "%d\n%d" , cm , z );      //printf("\n%c\n",str[1][2]);      return   0 ; }

Jumping On The Clouds

 Question :- https://www.hackerrank.com/challenges/jumping-on-the-clouds/problem Solution in C language :- #include< stdio.h > main () {      int   n , i , sum = 0 ;      scanf ( "%d" ,& n );      int   a [ n ];      for ( i = 0 ; i < n ; i ++)      scanf ( "%d" ,& a [ i ]);      for ( i = 0 ; i < n ;)      {          if ( a [ i + 1 ]== 0 && a [ i + 2 ]== 1 )          {              i = i + 1 ;              sum ++;          }          else          {              sum ++;              i = i + 2 ;          }            if ( i == n - 1 )          sum --;         }      printf ( "%d" , sum ); }

Repeated String

 Question :- https://www.hackerrank.com/challenges/repeated-string/problem Solution in C language :- #include< stdio.h > #include< string.h > int   main (){      long   long   int   n ;      char   s [ 100 ];      scanf ( "%s %lld" , s ,& n );      int   len = strlen ( s );      long   long   int   i , a = 0 ;      for ( i = 0 ; s [ i ]!= ' \ 0 ' ; i ++){          if ( s [ i ]== 'a' )              a ++;      }      long   long   int   t = n / len , temp = n % len ;      t = t * a ;      if ( temp != 0 ){          for ( i = 0 ; i < temp ; i ++){              if ( s [ i ]== 'a' )                  t ++;          }      }      printf ( "%lld" , t );      return   0 ; }

Cut The Sticks

 Question :- https://www.hackerrank.com/challenges/cut-the-sticks/problem Solution in C language :- #include< stdio.h > int   main (){      int   n ;      scanf ( "%d" ,& n );      int   a [ n ], i ;      for ( i = 0 ; i < n ; i ++){          scanf ( "%d" ,& a [ i ]);      }      int   temp = a [ 0 ], j , t = n , c = 0 , d = 0 ;      printf ( "%d\n" , n );      for ( j = 0 ; j < t ; j ++){          temp = 1000 ;          for ( i = 0 ; i < n ; i ++){              if ( a [ i ]> 0 ){                  if ( temp > a [ i ])                      temp = a [ i ];              }          }          for ( i = 0 ; i < n ; i ++){              a [ i ]= a [ i ]- temp ;              if ( a [ i ]> 0 )                  d ++;              if ( a [ i ]== 0 )                  c ++;          }          t = t - c + 1 ;          c = 0 ;          if ( d > 0 )              printf ( "%d\n" , d );         d = 0 ;      }      return   0

Library Fine

 Question :- https://www.hackerrank.com/challenges/library-fine/problem Solution in C language :- #include< stdio.h > int   main (){      int   d1 , d2 , m1 , m2 , y1 , y2 ;      scanf ( "%d%d%d%d%d%d" ,& d1 ,& m1 ,& y1 ,& d2 ,& m2 ,& y2 );      if ( d1 != d2   ||   m1 != m2   ||   y1 != y2 )      { if ( y1 >= y2 ){          if ( m1 > m2   &&   y1 == y2 ){              printf ( "%d" , 500 *( m1 - m2 ));          }          if ( m1 < m2   &&   y1 == y2 ){              printf ( "0" );          }          else   if ( d1 > d2   &&   m1 == m2   &&   y1 == y2 ){              printf ( "%d" , 15 *( d1 - d2 ));          }          else   if ( d1 < d2   &&   m1 == m2   &&   y1 == y2 ){              printf ( "0" );          }          else   if ( y1 > y2 ){              printf ( "10000" );          }      }      else   if ( y1 < y2 ){      

Sherlock and Squares

 Question :- https://www.hackerrank.com/challenges/sherlock-and-squares/problem Solution in C language :- #include   < stdio.h > #include   < string.h > #include   < math.h > #include   < stdlib.h > int   main (){ int   a , b ; scanf ( "%d" ); while ( scanf ( "%d%d" ,& a ,& b )> 0 ){      printf ( "%d\n" ,( int )( floor ( sqrt ( b ))- ceil ( sqrt ( a ))+ 1 ));} return   0 ;}

Append and Delete

 Question :- https://www.hackerrank.com/challenges/append-and-delete/problem Solution in C language :- #include< stdio.h > #include< string.h > int   main (){      char   a [ 100 ], b [ 100 ];      int   k ;      scanf ( "%s" , a );      scanf ( "%s" , b );      scanf ( "%d" ,& k );      int   la = strlen ( a ), lb = strlen ( b ), i , j , h , c = 0 , temp = 0 ; //    printf("%d %d\n",la,lb);      if ( la > lb ){          j = lb ;          h = la ;      }      else {          j = la ;          h = lb ;      }      for ( i = 0 ; i < j ; i ++){          if ( a [ i ]== b [ i ])              c ++;          else              break ;      }      if ( la + lb + 1 < k ){          printf ( "Yes" );          temp ++;      } //    printf("%d\n",c);      if ( la == lb   &&   la == c ){          if ( 2 * la == k - 1 )              printf ( "Yes" );          else   if ( k != 20   &&   2 * la