প্রবলেমটি পড়ুন এবং বুঝুন
#include<iostream>
#include<string>
using namespace std;
void justify(char *ch)
{
string o="one",t="two",th="three";
int i=0,counter[3]={0};
while(*(ch+i)!='\0')
{
if(o[i]==*(ch+i))
counter[0]+=1;
else if(t[i]==*(ch+i))
counter[1]+=1;
else if(th[i]==*(ch+i))
counter[2]+=1;
i++;
}
int v,maximum=0;
for(i=0;i<3;i++)
{
if(maximum<=counter[i])
{
maximum=counter[i];
v=i;
}
}
if(v==0)
cout<<"1\n";
else if(v==1)
cout<<"2\n";
else if(v==2)
cout<<"3\n";
}
int main()
{
int test;
cin>>test;
while(test--)
{
string str;
cin>>str;
justify(&str[0]);
}
return 0;
}
#include<iostream>
#include<string>
using namespace std;
void justify(char *ch)
{
string o="one",t="two",th="three";
int i=0,counter[3]={0};
while(*(ch+i)!='\0')
{
if(o[i]==*(ch+i))
counter[0]+=1;
else if(t[i]==*(ch+i))
counter[1]+=1;
else if(th[i]==*(ch+i))
counter[2]+=1;
i++;
}
int v,maximum=0;
for(i=0;i<3;i++)
{
if(maximum<=counter[i])
{
maximum=counter[i];
v=i;
}
}
if(v==0)
cout<<"1\n";
else if(v==1)
cout<<"2\n";
else if(v==2)
cout<<"3\n";
}
int main()
{
int test;
cin>>test;
while(test--)
{
string str;
cin>>str;
justify(&str[0]);
}
return 0;
}
No comments:
Post a Comment