Md Shahjahan
BAN USERI have improved the solution.....
You can enter any string...of any length....(20 is boundry)....
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[20][20],b[20],c[20],ch;
static int i,j,k;
printf("Enter the string:\n");
ch=getchar();
do
{
if(ch==' ')
{
a[i][j]='\0';
i++;
j=0;
}
else if(ch=='\n')
{
a[i][j]='\0';
}
else
{
a[i][j++]=ch;
}
} while((ch=getchar())!='\n');
printf("Enter the string to be replaced:");
gets(b);
printf("\nEnter the string by which replacement is to be done:");
gets(c);
for(k=0;k<=i;k++)
{
if(strcmp(a[k],b)==0)
{
strcpy(a[k],c);
}
}
for(k=i;k>=0;k--)
{
fputs(a[k],stdout);
printf(" ");
}
getch();
}
An efficient solution in c code
#include<stdio.h>
#include<conio.h>
void main()
{
char a[20];
static int i,j,n;
printf("Enter the string:");
gets(a);
for(i=0;;)
{
for(j=i;a[j]==a[i];j++)
{
n++;
}
if(n>1)
printf("%c%d",a[i],n);
else
printf("%c",a[i]);
n=0;
i=j;
if(a[i]=='\0')
break;
}
getch();
}
}
- Md Shahjahan October 13, 2013//career cup problum
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[5][20];
static int i,j,count[5]={0},k,max;
printf("Enter 5 strings:\n");
for(i=0;i<5;i++)
{
gets(a[i]);
}
for(j=0;j<5;j++)
{
for(i=0;i<5;i++)
{
if(strstr(a[j],a[i])!=NULL)
count[j]++;
}
max=count[0];
if(max<count[j])
{ max=count[j];
k=j;
}
}
//for(i=0;i<5;i++)
//{
// printf("%d",count[i]);
//}
printf("THE STRING CONTAINING MAX . NO OF OTHER IS GIVEN BY:");
puts(a[k]);
getch();
}
}
- Md Shahjahan October 13, 2013
Algorithm:
1.store abcde...in a 2-D array
2.Search for row
3.If row is greater than the previous row value,move down otherwise move up.In case of no changing in row donot move up or down.
4.Now look for column and move right or left correspondingly....
Remember initial position to be (0,0)
I have implemented in C using turbo C++ compiler
- Md Shahjahan October 21, 2013