#include<bits/stdc++.h>
using namespace std;
string substring(string ch)
{
int l = ch.size(), i, j, f = 0;
string an = "";
string bc = "";
an.push_back(ch[0]);
an.push_back(ch[1]);
bc.push_back(ch[0]);
for(i=2; i<l; i++)
{
if(an[0] == ch[i] && an[1] == ch[i+1])
{
int ll = an.size();
int k = i;
for(j=0; j<ll && k<l; j++, k++)
{
if(an[j] == ch[k])
{
f = 1;
}
else
{
f = 0;
break;
}
}
bc.push_back(ch[i]);
}
if(i == l-1 && a[0] == ch[])
else if(f==0)
{
an.push_back(ch[i]);
bc.push_back(ch[i]);
}
else
{
bc.push_back(ch[i]);
}
}
cout << j << endl;
if(j != an.size())
{
cout << "bc :" << endl;
cout << an << endl;
return bc;
}
if(f == 1)
{
cout << "an : " << endl;
return an;
}
else
{
cout << "1bc : " << endl;
return bc;
}
}
int main()
{
string a, b;
int n, i;
while(cin >> n)
{
for(i=1; i<=n; i++)
{
cin >> a;
b = substring(a);
int c = b.size();
if(i > 1)
cout << endl;
cout << c << endl;
}
}
return 0;
}
using namespace std;
string substring(string ch)
{
int l = ch.size(), i, j, f = 0;
string an = "";
string bc = "";
an.push_back(ch[0]);
an.push_back(ch[1]);
bc.push_back(ch[0]);
for(i=2; i<l; i++)
{
if(an[0] == ch[i] && an[1] == ch[i+1])
{
int ll = an.size();
int k = i;
for(j=0; j<ll && k<l; j++, k++)
{
if(an[j] == ch[k])
{
f = 1;
}
else
{
f = 0;
break;
}
}
bc.push_back(ch[i]);
}
if(i == l-1 && a[0] == ch[])
else if(f==0)
{
an.push_back(ch[i]);
bc.push_back(ch[i]);
}
else
{
bc.push_back(ch[i]);
}
}
cout << j << endl;
if(j != an.size())
{
cout << "bc :" << endl;
cout << an << endl;
return bc;
}
if(f == 1)
{
cout << "an : " << endl;
return an;
}
else
{
cout << "1bc : " << endl;
return bc;
}
}
int main()
{
string a, b;
int n, i;
while(cin >> n)
{
for(i=1; i<=n; i++)
{
cin >> a;
b = substring(a);
int c = b.size();
if(i > 1)
cout << endl;
cout << c << endl;
}
}
return 0;
}
Comments
Post a Comment