ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1197. Lonesome Knight

W.A. 2 Help me
Posted by Alexsey 6 Jul 2014 20:33
#include <iostream>
#include <string>


using namespace std;


int main()
{
    int n;
    cin>>n;
    int p[n];
    string posi;
    for(int i=0; i<n; i++)
    {
        cin>>posi;
        if ((posi[0]<'a'||posi[0]>'h')||(posi[1]<'1'||posi[1]>'8'))
            return 0;
        if (posi[0]>='c'&&posi[0]<='f')
        {
            if (posi[1]>='3'&&posi[1]<='6')
                p[i]=8;
            if (posi[1]=='2'||posi[1]=='7')
                p[i]=6;
            if (posi[1]=='1'||posi[1]=='0')
                p[i]=4;
        }
        if (posi[0]=='b'||posi[0]=='g')
        {
            if (posi[1]>='3'&&posi[1]<='6')
                p[i]=6;
            if (posi[1]=='2'||posi[1]=='7')
                p[i]=4;
            if (posi[1]=='1'||posi[1]=='8')
                p[i]=3;
        }
        if (posi[0]=='a'||posi[0]=='h')
        {
            if (posi[1]>='3'&&posi[1]<='6')
                p[i]=4;
            if (posi[1]=='2'||posi[1]=='7')
                p[i]=3;
            if (posi[1]=='1'||posi[1]=='8')
                p[i]=2;
        }
    }
    for (int i=0; i<n; i++)
        cout<<p[i]<<endl;

    return 0;
}
Re: W.A. 2 Help me
Posted by mhg 20 Jul 2014 20:07
hi,in your code you should consider 'a','h',1,8.
 for example :if ((posi[0]<='a'||posi[0]>='h')||(posi[1]<='1'||posi[1]>='8'))