Goat Research


This is a companion discussion topic for the original entry at https://toph.co/p/goat-research

all output match…but not accepted.

#include<iostream>
using namespace std;

int main()
{

	int n;
	string s[20];
	cin >> n;
	if (n < 20)
	{

		for (int i = 0; i < n; i++)
		{
			string q;
			cin >> q;
			int f = q.length();
			if (f <= 20)
			{
				if (q.at(0) == 'b')
				{
					int z = 0;
					int k = 0;
					for (int i = 1; i < f; i++)
					{
						if (q[i] == 'a')
						{
							z++;
						}
						else if (q[i] != 'a')
						{
							k++;
						}

					}
					if (z >= 1 && k == 0)
					{
						if (z == 1)
						{

							for (int i = 0; i <= f; i++)
							{
								if ((i+1) == f)
								{
								    q.resize(f+1);
									q.at(i+1) = 'a';
								}

							}
							s[i] = q;
						}



						else if (z > 1)
						{
						    if(z%2==1)
                            {
							f - 1;
							for (int i = 0; i < f; i++)
							{
								if (i == (f - 1))
								{
									q[i] = NULL;
								}

							}
							s[i] = q;
                            }
                            else
                              {
                                s[i]=q;
                              }

						}


					}



				}
			}
		}

		int xx = 0;
		int maxlen = 0;
		for (int i = 0; i < n; i++)
		{
			if (s[i].empty()==false)
			{
				xx = s[i].length();
				if (xx > maxlen)
				{
					maxlen = xx;
				}

			}


		}
		int maxdev = 20 - maxlen;
		if (maxdev >= 0)
		{
			maxdev = maxdev / 2;
			for (int i = 0; i < n; i++)
			{
				int size = 0;
				size = s[i].length();
				int div = 20 - size;
				if (div >= 0)
				{
					div = div / 2;
					div = div - maxdev;
					for (int i = 0; i < div; i++)
					{
						cout << " ";

					}
					cout << s[i] << endl;
				}
				else
                {
                    cout<<s[i];
                }

			}

		}
	}







}

Don’t know why but your code is printing some NoN-ASCII characters at the end.
see this https://www.diffchecker.com/Yh6ARDO9 .

thanks vai…i’ve solved the problem.and finally it accepted.thanks a lot vai

vai,i got WA in test case 2. test case dile upokar hoto.
my code:

#include<bits/stdc++.h>
#include<list>
#define fread freopen("in.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdin)

#define ll long long int
#define PI acos(-1)
#define MAX 1000000007

using namespace std;

vector< int >vec;
list<char >l;
list<char >::iterator it;

int main()
{
   /// fread;
   // fwrite;
    int n;
    cin>>n;
    while(n--)
    {
        string s;int i=0;
        cin>>s;
        while(s[i]!='\0')
        {
            l.push_back(s[i++]);
        }
       // for(it = l.begin();it!=l.end();it++)cout<<*it<<endl;
        int si = l.size();

        if(si==1)
        {
            l.push_back('a');
            l.push_back('a');
        }
        else if(si==2)l.push_back('a');
        else if(si%2)
        {

        }
        else
        {
            l.reverse();
            it = l.begin();
            l.erase(it);
            l.reverse();
        }
        if(si==1 || si==2 || si == 3 || si == 4){
                it=l.begin();
            l.insert(it,' ');
            l.insert(it,' ');
            l.insert(it,' ');
            l.insert(it,' ');
        }
        else if(si==6 || si == 5)
        {
            it=l.begin();
            l.insert(it,' ');
            l.insert(it,' ');
            l.insert(it,' ');
        }
        else if(si==7 || si == 8)
        {
            it=l.begin();
            l.insert(it,' ');
            l.insert(it,' ');
        }
        else if(si==9 || si == 10)
        {
            it=l.begin();
            l.insert(it,' ');
        }
        for(it = l.begin();it!=l.end();it++)
        {
            cout<<*it;
        }
        l.clear();
        cout<<endl;
    }
    return 0;
}
times = int(input())
lis = list()
for i in range(1,times +1):
    string = input()
    index = string.rfind("a")
    if index%2 !=0:
        nstring = string[0:index]
        nindex = nstring.rfind("a")
        if(nindex == -1):
           lis.append("ba")
        else:
            lis.append(nstring)
    else:
        lis.append(string)
maxl = len(max(lis,key=len))
for x in lis:
    
    
    print(x.center(maxl))

my code gives right answer in my editor but does not pass the tests. can anyone explain where am I moving wrong?