Robo dialy activities first eat ,then computer and then sleep (ecs)
The day starts with eat he can do eat/computer/sleep
if the day starts with computer he can do computer/sleep
The day starts with sleep he can do only sleep
I/p
Ex: ecs o/p Success
Ex: ces o/p Fail
Ex: eeccsss o/p success
Ex: ecse o/p Fail
#include<stdio.h>
#include<string.h>
#include<conio.h>
char pat[]="ecs";
int prev=0,curr=0;
int check(char ch1,char ch2)
{
int i;
for(i=0;pat[i]!=0;i++)
if(pat[i]==ch1)
curr=i;
for(i=0;pat[i]!=0;i++)
if(pat[i]==ch2)
prev=i;
if(curr<prev)
return 0;
else
return 1;
}
void main()
{
/* ces cceess */
char str[]="ssss";
int i=1;
clrscr();
while(str[i]!=0)
{
if(check(str[i],str[i-1]))
{
i++;
}
else
break;
}
if(i==strlen(str))
printf("\n....Success",i);
else
printf("\nFail",i);
}
No comments:
Post a Comment