mardi 3 décembre 2019

Reading test cases

How can I read test cases in a file where its unknown how many test cases are there in a file. Actually I'm trying to solve the knight moves problem >>> online judge. The input discription for the question is given as below:

Input
The input file will contain one or more test cases. Each test case consists of one line containing two squares separated by one space. A square is a string consisting of a letter (a..h) representing the column and a digit (1..8) representing the row on the chessboard.

Sample Input
e2 e4
a1 b2
b2 c3
a1 h8
a1 h7
h8 a1
b1 c3
f6 f6
Attempts
With the following method i tried on code block and i get correct results(with all the full code) but when I submit on online judge it says wrong answer could it be that my input method is not correct?

vector<string> pos;
char input[6];

for(;;){
        cin.getline(input,sizeof(input));
        if(input[0]!='\0'){
            pos.push_back(input);
        }
        else{
            break;
        }
}

Aucun commentaire:

Enregistrer un commentaire