Example #1
0
File: b115.c Project: gsrr/Programs
int main()
{
	char num1[100];
	char num2[100];
	char op[2];
	while(scanf("%s",num1) != EOF)
	{
		getchar();
		scanf("%s", op);
		scanf("%s", num2);
		reverseStr(num1);
		reverseStr(num2);

		char ret[100] = {0};
			if(op[0] == '*')
			{
				bigMulChar(num1, num2, ret);
			}
			else
			{
				bigDivide(num1, num2, ret);
			}
			reverseStr(ret);
			printf("%s\n", ret);
	}
	return 0;
}
    string reverseSentence(string sentence) {
        if (sentence.length()<1) {
            return NULL;
        }

        int senLength = 0;
        for (int i = 0; sentence[i] != '\0'; i++) {
            senLength++;
        }

        reverseStr(sentence, 0, senLength - 1);

        for (int i = 0, j = 0; i < senLength;) {
            if (sentence[i] == ' ') {
                i++;
                j++;
            }
            else if (sentence[j] == ' ' || sentence[j] == '\0') {
                reverseStr(sentence, i, j - 1);
                i = j;
            }
            else {
                j++;
            }
        }

        return sentence;
    }
    string leftRotateString(string word,int n) {
        if(word.length()<1) {
            return NULL;
        }

        reverseStr(word,0,n-1);
        reverseStr(word,n,word.length()-1);
        reverseStr(word, 0, word.length() - 1);
        return word;
    }
 void reverseWords(string &s) {
     int sz = s.size();
     reverseStr(s, 0, sz - 1);
     int start = 0;
     for (int i = 0; i < sz; ++i) {
         if (s[i] == ' ') {
             reverseStr(s, start, i - 1);
             start = i + 1;
         }
     }
     reverseStr(s, start, sz - 1);
 }
Example #5
0
File: b115.c Project: gsrr/Programs
void getMultTemp(char arr[], int index)
{
	reverseStr(arr);
	int len = strlen(arr);
	int i;
	for( i = len ; i < len + index ; i++ )
	{
		
		arr[i] = '0';	
	}
	arr[i] = '\0';
	reverseStr(arr);
}
Example #6
0
int main()
{
char a_str[]= {"Hello, World."};
reverseStr(a_str);
printf("After a string is reversed, you got: %s\n", a_str);
return 0; 
}
Example #7
0
int main()
{

    char *tt= "ciaoo";
    char * res ;
    res= reverseStr(tt);
    printf("string invertita:%s dada\n", res);
    return 0;
}
Example #8
0
/*Converts answer to hexadecimal string with the type and negative. */
char* toHex(int ans) {
	char* result = (char*) malloc(sizeof(char)*33);
	int i = 0;
	int mem = ans;
	
	if (ans == 0) {
		result[0] = '0';
		result[1] = '\0';
		return result;
	}
	
	if (ans < 0)
		ans = ans*-1;
	
	while (ans != 0) {
		int b = ans%16;
		if (b < 0)
			b = b*-1;
		if (b == 10) {
			result[i] = 'a';
		}
		else if (b == 11) {
			result[i] = 'b';
		}
		else if (b == 12) {
			result[i] = 'c';
		}
		else if (b == 13) {
			result[i] = 'd';
		}
		else if (b == 14) {
			result[i] = 'e';
		}
		else if (b == 15) {
			result[i] = 'f';
		}
		else {
			result[i] = b + '0';
		}
		i++;
		ans = ans/16;		
	}
	
	result[i] = 'x';
	i++;
	
	if (mem < 0) {
		result[i] = '-';
		i++;
	}
		
	result[i] = '\0';
	reverseStr(result);
	
	return result;
}
Example #9
0
string MyLib::int2String(int x){
	if(x == 0) return "0";
	string ans = "";
	while(x){
		ans += (char)('0'+x%10);
		x /= 10;
	}
	reverseStr(ans);
	return ans;
}
Example #10
0
int main() {
    printf("Goal: left shift \"%s\" by %d position using algorithm 1\n", mystr, sft_idx);
    printf("String before shift is : %s\n", mystr);
    if (sft_idx > strlen(mystr)) {
        fprintf(stderr, "Shift Index can NOT be larger than string length.\n");
        return 0;
    } else if (sft_idx == strlen(mystr)) {        
        printf("String after  shift is : %s\n", mystr);
        return 0;
    } 

    reverseStr(0, sft_idx-1);
    reverseStr(sft_idx,strlen(mystr)-1);
    reverseStr(0, strlen(mystr)-1);

    printf("String after  shift is : %s\n", mystr);

    return 0;
}
Example #11
0
File: b115.c Project: gsrr/Programs
void bigDivide(char num1[] , char num2[] , char quot[])
{
	if(strcmp(num1 , "0") == 0)
	{
		quot[0] = '0';
		quot[1] = '\0';
		return;
	}
	char *temp = (char*)malloc(sizeof(char) * strlen(num1));
	int len1 = strlen(num1);
	int i;
	int j = 0;
	for( i = 0 ; i < len1 ; i++)
	{
		temp[j] = num1[len1-i-1];
		temp[j+1] = '\0';
		reverseStr(temp);
		int cnt = 0;
		while(isBigger(temp , num2))
		{
			bigSub(temp, num2);
			cnt++;
		}
		reverseStr(temp);
		quot[i] = cnt + '0';

                if(strcmp(temp, "0") == 0)
                {
                        j = 0;
                }
                else
                {
                        j++;
                }
	}
	quot[i] = '\0';
	removeFrontZero(quot);
	reverseStr(quot);
	free(temp);
}
Example #12
0
int isPalindrome(char *str)
{
	char temp[MAX_SIZE];

	cleanStr(str);
	copyStr(str, temp);
	reverseStr(temp);

	if(isEqual(str, temp)){
		return 1;
	}

	return 0;
}
Example #13
0
int main(){
	int i;
	int elem[10] = {6,3,8,2,5,9,4,5,1,7};
	char s[] = "12345678";
	//int elem[10] = {1,2,3,4,5,6,7,8,9,10};
	//quickSort(elem,0,sizeof(elem)/sizeof(int));
	shellsort(elem,sizeof(elem)/sizeof(int));
	for(i = 0; i < sizeof(elem)/sizeof(int) ; i++)
		printf("%d " , elem[i]);
	printf("\n");
	reverseStr(s,0,strlen(s)-1);
	printf("%s \n",s);
	return 0;
}
Example #14
0
/*Converts answer to binary, octal or decimal string with type and negative*/
char* toStr(char type, int ans) {
	char* result = (char*) malloc(sizeof(char)*33);
	int i = 0;
	int num = 0;
	int mem = ans;
	
	if (type == 'd' || type == 'D') {
		num = 10;
	}
	else if (type == 'o' || type == 'O') {
		num = 8;
	}
	else if (type == 'b' || type == 'B') {
		num = 2;
	}
	
	if (ans == 0) {
		result[0] = type;
		result[1] = '0';
		result[2] = '\0';
		return result;
	}
	
	while (ans != 0) {
		int b = ans%num;
		if (b < 0)
			b = b*-1;
		result[i] = b + '0';
		i++;
		ans = ans/num;		
	}
	
	result[i] = type;
	i++;
	
	if (mem < 0) {
		result[i] = '-';
		i++;
	}
	
	result[i] = '\0';
	
	reverseStr(result);
	
	return result;
}
int main (int argc, char* argv[]) {
	char* i_str = "!sseccus";
	char* o_str;
	if(argc > 1) {
		i_str = argv[1];
	}
	
	o_str = reverseStr(&i_str);

	printf("o_str: %s\n", o_str);

	free(i_str);
	free(o_str);

	printf("Job's Done.\n");
	return 0;
}
Example #16
0
int main()
{
    char str[200],get[200],set[200];
    while(gets(str) && strcmp(str,"DONE"))
    {
        int i=0,j;
        for(i=0,j=0;str[i]!='\0';i++)
            if(isalpha(str[i]))
                set[j++]=tolower(str[i]);
        set[j] = '\0';

        reverseStr(set,get);
        if(strcmp(set,get)==0)
            printf("You won't be eaten!\n");
        else
            printf("Uh oh..\n");
    }
    return 0;
}
void getBinaryRepresentation(int num, int numDigit, char str[])
{
	int lenStr = 0, digit;

	while(num)
	{
		digit = num & 1;
		str[lenStr] = (char) (digit + '0');
		lenStr++;
		num >>= 1;	
	}

	while(lenStr < numDigit)
	{
		str[lenStr] = '0';
		lenStr++;
	}

	str[lenStr] = '\0';

	reverseStr(str, lenStr);	
}
Example #18
0
void reversePathDirection(char str[]) 
{
	//takes the path from the finish point back to the starting point, and transforms it to become a path for the other way around

	//adds an 'S' to the end of the string
	int length = strlen(str);
	str[length] = 'S';
	str[length+1] = '\0';

	reverseStr(str);

	int i = 0;
	while(str[i] != '\0')
	{
		//swap 'R's with 'L's, since left/right is reversed when tracking back
		if(str[i] == 'R') { str[i] = 'L'; }
		else if(str[i] == 'L') { str[i] = 'R'; }
		i++;
	}

	str[strlen(str) - 1] = '\0'; //remove the 'B' at the end
}
Example #19
0
void main(void){
	char str[]="abcdefgh";
	reverseStr(str);
	printf("%s\n",str);
}
Example #20
0
void reverseStr(char * s, int lo , int hi){
	if(lo >= hi) return;
	swap_t(char , s[lo],s[hi]);
	reverseStr(s,++lo,--hi);
}