int karatSuba( char * num1, char * num2 ){
    int n1,n2 ;
    n1 = convert_to_int(num1);
    n2 = convert_to_int(num2);

    if ( n1 < 10 || n2 < 10 ){
        return n1*n2 ;
    }
    int m = max(num1,num2,10)/2;

    // high1, low1 = split_at(num1,m2);
    char * high1 = split_at(num1,0,m);
    char * low1 = split_at(num1,m,strlen(num1));
    // high2, low2 = split_at(num2,m2);
    char * high2 = split_at(num2,0,m);
    char * low2 = split_at(num2,m,strlen(num2));

    int z0 = karatSuba(low1,low2);
    int z1 = karatSuba(convert_to_char(convert_to_int(low1)+convert_to_int(high1)),(convert_to_char(convert_to_int(low2)+convert_to_int(high2))));
    int z2 = karatSuba(high1,high2);
    return (z2*pow(10,2*m))+((z1-z2-z0)*pow(10,m))+z0;
}
int main(){
    char * num1 ;
    char * num2 ;
    num1 = readInput(1);
    num2 = readInput(2);

    printf("\nConverted to int:%d",convert_to_int(num1));
    printf("\nConverted to char:%s",convert_to_char(convert_to_int(num1)));
    printf("\nMax:%d",max(num1,num2,10));
    printf("\nSplit at 0-3:%s",split_at(num1,0,3));
    printf("\nSplit at 3-5:%s",split_at(num1,3,strlen(num1)));
    printf("\nKaratsuba:%d",karatSuba(num1,num2));

    return 0 ;
}
Beispiel #3
0
void find_duplicates_sorted(char *a){
  int h[26],i;
  int len=strlen(a);
	if(len==0)printf("empty string");

	for(i=0;i<26;i++)
		h[i]=0;

	//Now traverse string
	for(i=0;i<len;i++)
		h[convert_to_int(*(a+i))]++;

	//Get duplicates now
		for(i=0;i<26;i++)
		  if(h[i]>1)
        printf("%c\n",convert_to_char(i));

		}