problem link:
Discuss: this is simple implementation problem.you can solve it with just one loop.
try yourself before see the code
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str;
while(getline(cin,str))
{
if(str=="*")
break;
int n,i,j,cnt=0,flag=0;
char ch;
n=str.length();
for(i=0;i<n;i++)
str[i]=tolower(str[i]);
ch=tolower(str[0]);
for(i=0;i<n;i++)
{
str[i]=tolower(str[i]);
if(str[i]==' ')
{
if(str[i+1]!=ch)
{
flag=1;
break;
}
}
if(flag)
break;
}
if(!flag)
cout <<'Y'<<endl;
else
cout <<'N'<<endl;
}
return 0;
}
Discuss: this is simple implementation problem.you can solve it with just one loop.
try yourself before see the code
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str;
while(getline(cin,str))
{
if(str=="*")
break;
int n,i,j,cnt=0,flag=0;
char ch;
n=str.length();
for(i=0;i<n;i++)
str[i]=tolower(str[i]);
ch=tolower(str[0]);
for(i=0;i<n;i++)
{
str[i]=tolower(str[i]);
if(str[i]==' ')
{
if(str[i+1]!=ch)
{
flag=1;
break;
}
}
if(flag)
break;
}
if(!flag)
cout <<'Y'<<endl;
else
cout <<'N'<<endl;
}
return 0;
}
No comments:
Post a Comment