#include "time.h"
#include "math.h"
#include "assert.h"
int num_tests = 5000000 ;
unsigned duck( unsigned x, unsigned y) {
}
int myPow( int x, int p)
{
if ( p == 0 ) return 1 ;
if ( p == 1 ) return x;
int tmp = myPow( x, p/ 2 ) ;
if ( p% 2 == 0 ) return tmp * tmp;
else return x * tmp * tmp;
}
int david( int x, int y) {
return x* myPow( 10 , power+ 1 ) + y;
}
int drummer( int x, int y) {
int shifted
= x
* pow ( 10 , digits
) ; // will be 1100 in your example return shifted + y; // 1111
}
int shabeer( int x, int y) {
int temp= 0 ;
int z= x;
while ( y> 0 )
{
// take reciprocal of y into temp
temp= ( temp* 10 ) + ( y% 10 ) ;
y= y/ 10 ;
}
while ( temp> 0 )
{
// take each number from last of temp and add to last of z
z= ( z* 10 ) + ( temp% 10 ) ;
temp= temp/ 10 ;
}
return z;
}
int gokcehan( int x, int y) {
int temp = y;
while ( y != 0 ) {
x *= 10 ;
y /= 10 ;
}
return x + temp;
}
void int_time( const char * name, unsigned ( * func) ( unsigned , unsigned ) ) {
unsigned r = 0 ;
unsigned i = 0 ;
for ( ; i< num_tests; ++ i)
r += func( i, i) ;
}
void uint_time( const char * name, int ( * func) ( int , int ) ) {
unsigned r = 0 ;
unsigned i = 0 ;
for ( ; i< num_tests; ++ i)
r += func( i, i) ;
}
void uint_accuracy( const char * name, unsigned ( * func) ( unsigned , unsigned ) ) {
printf ( "testing %s accuracy: " , name
) ; assert ( func
( 23 , 456 ) == 23456 ) ; assert ( func
( 234 , 56 ) == 23456 ) ; }
void int_accuracy( const char * name, int ( * func) ( int , int ) ) {
printf ( "testing %s accuracy: " , name
) ; assert ( func
( 1 , 0 ) == 10 ) ; //several fail this one assert ( func
( 10 , 0 ) == 100 ) ; //several fail this one assert ( func
( 23 , 456 ) == 23456 ) ; assert ( func
( 234 , 56 ) == 23456 ) ; }
int main( ) {
uint_time( "duck" , duck) ;
uint_time( "duck" , duck) ;
int_time( "david" , david) ;
int_time( "david" , david) ;
int_time( "drummer" , drummer) ;
int_time( "drummer" , drummer) ;
int_time( "shabeer" , shabeer) ;
int_time( "shabeer" , shabeer) ;
int_time( "gokcehan" , gokcehan) ;
int_time( "gokcehan" , gokcehan) ;
uint_accuracy( "duck" , duck) ;
//int_accuracy("gokcehan", gokcehan); //Assertion `func(1, 0) == 10' failed.
//int_accuracy("drummer", drummer); //Assertion `func(1, 0) == 10' failed.
//int_accuracy("david", david); //Assertion `func(1, 0) == 10' failed.
//int_accuracy("shabeer", shabeer); //Assertion `func(0, 10) == 10' failed.
return 0 ;
}
I2luY2x1ZGUgInRpbWUuaCIKI2luY2x1ZGUgIm1hdGguaCIKI2luY2x1ZGUgImFzc2VydC5oIgoKaW50IG51bV90ZXN0cyA9IDUwMDAwMDA7Cgp1bnNpZ25lZCBkdWNrKHVuc2lnbmVkIHgsIHVuc2lnbmVkIHkpIHsKICAgIHVuc2lnbmVkIHBvdyA9IDEwOwogICAgd2hpbGUoeSA+PSBwb3cpCiAgICAgICAgcG93ICo9IDEwOwogICAgcmV0dXJuIHggKiBwb3cgKyB5OyAgICAgICAgCn0KaW50IG15UG93KGludCB4LCBpbnQgcCkKewogICAgIGlmIChwID09IDApIHJldHVybiAxOwogICAgIGlmIChwID09IDEpIHJldHVybiB4OwoKICAgICBpbnQgdG1wID0gbXlQb3coeCwgcC8yKTsKICAgICBpZiAocCUyID09IDApIHJldHVybiB0bXAgKiB0bXA7CiAgICAgZWxzZSByZXR1cm4geCAqIHRtcCAqIHRtcDsKfQppbnQgZGF2aWQoaW50IHgsIGludCB5KSB7CiAgICBpbnQgcG93ZXIgPSBsb2cxMCh5KTsKICAgIHJldHVybiB4Km15UG93KDEwLHBvd2VyKzEpK3k7Cn0KCmludCBkcnVtbWVyKGludCB4LCBpbnQgeSkgewogICAgaW50IGRpZ2l0cyA9IGxvZzEwKHkpKzE7CiAgICBpbnQgc2hpZnRlZCA9IHggKiBwb3coMTAsIGRpZ2l0cyk7ICAgLy8gd2lsbCBiZSAxMTAwIGluIHlvdXIg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