kalyan359
BAN USER#include <stdlib.h>
#include <stdio.h>
char* remove_spaces(char *str)
{
char *ptr2;
ptr2=str;
while(*str !='\0')
{
if(*str == ' ')
{
*str = ++*str;
str++;
}
else
{
str++;
}
}
return ptr2;
}
int main()
{
char s[100];
printf("\n Enter the String:")
gets(s);
char *ans;
ans = remove_spaces(s);
printf("\n The string without spaces is %s",ans);
return 0;
}
Hi all,
Here is a simple solution for this problem.
step1: Identify minimum value present in each row. This takes O(n) time for 1 row.Store the column number and least value in a Table.
step 1.1: If you encounter a column number being repeated, store the minimum value for that the column.
Step 2: Now, we have a column and its corresponding value. Check to see if the value is the least value in the column, if yes. Print it as out put, else display "such number do not exist".
So total run time of Algorithm is O(n^2)
A minor correction to the above code is to initialize i to (size-1) instead of size in the second for loop above.
- kalyan359 November 29, 2012