Posts

Showing posts from September, 2016

UVA 10101 - Bangla Numbers Solution

# include < cstdio > # include < cstring > using namespace std ; int main ( ) { long long int tc = 0 , n ; while ( scanf ( " %lld " , & n ) ! = EOF ) { printf ( " %4lld . " , + + tc ) ; if ( n = = 0 ) { printf ( " 0 \n " ) ; continue ; } int a [ 20 ] = { 0 } , i = 14 ; while ( n ) { a [ i - - ] = n % 10 ; n / = 10 ; } //printf("%d\n",i); int b = a [ 0 ] ; if ( b ) printf ( " %d kuti " , b ) ; b = a [ 1 ] * 10 + a [ 2 ] ; if ( b ) printf ( " %d lakh " , b ) ; b = a [ 3 ] * 10 + a [ 4 ] ; if ( b ) printf ( " %d hajar " , b ) ; b = a [ 5 ] ; if ( b ) printf ( " %d shata " , b ) ; b = a [ 6 ] * 10 + a [ 7 ] ; if ( b ) printf ( " %d " , b ) ; if ( i < 7 ) printf ( " kuti " )...

UVA 11503 - Virtual Friends Solution

# include < iostream > # include < cstdio > # include < string > # include < vector > # include < map > # include < algorithm > using namespace std ; class DS { private : vector < int > parent , rank , setSize ; int numSets ; public : DS ( int n ) { numSets = n ; parent . assign ( n , 0 ) ; rank . assign ( n , 0 ) ; setSize . assign ( n , 1 ) ; for ( int i = 0 ; i < n ; i + + ) parent [ i ] = i ; } int findParent ( int i ) { return parent [ i ] = = i ? i : parent [ i ] = findParent ( parent [ i ] ) ; } bool isSame ( int i , int j ) { return findParent ( i ) = = findParent ( j ) ; } void unionSet ( int x , int y ) { int xRoot = findParent ( x ) ; int yRoot = findParent ( y ) ; if ( xRoot = = yRoot ) return ; if ( rank [ xRoot ] > rank [ yRoot ] ) { ...

Codeforces 716A Solution

# include < bits/stdc++.h > using namespace std ; int main ( ) { int n , c ; scanf ( " %d %d " , & n , & c ) ; int ans = 0 ; int d = 0 ; while ( n - - ) { int t ; scanf ( " %d " , & t ) ; if ( t - d > c ) ans = 1 ; else ans + + ; d = t ; } printf ( " %d \n " , ans ) ; return 0 ; }