Problem link-click here
it's an easy implement based string processing problem. just read the problem statement carefully.
an accepted code is as follows:
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str;
int q=1,n;
while(cin>>str)
{
cout<<"Case "<<q<<":"<<endl;
bool s;
cin>>n;
while(n--)
{
int a,b;
cin>>a>>b;
if(b<a)
{
int temp=a;
a=b;
b=temp;
}
char ch;
s=true;
ch=str[a];
for(int i=a+1;i<=b;i++)
{
if(ch!=str[i])
{
s=false;
break;
}
}
if(s)
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
}
q++;
}
return 0;
}
it's an easy implement based string processing problem. just read the problem statement carefully.
an accepted code is as follows:
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str;
int q=1,n;
while(cin>>str)
{
cout<<"Case "<<q<<":"<<endl;
bool s;
cin>>n;
while(n--)
{
int a,b;
cin>>a>>b;
if(b<a)
{
int temp=a;
a=b;
b=temp;
}
char ch;
s=true;
ch=str[a];
for(int i=a+1;i<=b;i++)
{
if(ch!=str[i])
{
s=false;
break;
}
}
if(s)
{
cout<<"Yes"<<endl;
}
else
{
cout<<"No"<<endl;
}
}
q++;
}
return 0;
}
No comments:
Post a Comment