| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
for which input is my code for problem 1204 not working , but online judge gives me a wrong answer messagemy code is
#include <iostream>
#include <string>
#include <vector>
using namespace std ;
struct ans
{
int row,col;
char dir ;
};
int main ()
{
int n ;
int rows,cols;
cin>>rows>>cols>>n;
vector <string> keys;
vector <string> map ;
vector <ans> answers ;
int i ;
for( i =0 ;i<rows;i++)
{
string temp;
cin>>temp ;
map.push_back(temp);
}
for (i=0;i<n;i++)
{
string temp ;
cin>>temp ;
keys.push_back(temp);
}
for ( i = 0 ; i < keys.size() ; i ++ )
{
string word =keys.at(i);
ans a ;
for ( int r = 0 ; r < rows ; r ++ )
{
for ( int c = 0 ; c < cols ; c++ )
{
if( word.at(0) == map.at(r).at(c) )
{
int len = word.length();
if(c +len <= cols )//east
{
bool found = true ;
for ( int i = 1 ; i < len ; i ++ )
{
if(word.at(i) != map.at(r).at(c+i))
{
found = false ;
break ;
}
}
if(found) { a.row = r; a.col=c ; a.dir='C';goto nextword;}
}
if(c-len >= -1 )//west
{
bool found = true ;
for ( int i = 1 ; i < len ; i ++ )
{
if(word.at(i) != map.at(r).at(c-i))
{
found = false ;
break ;
}
}
if(found){a.row = r; a.col=c ; a.dir='G';goto nextword;}
}
if(r +len <= rows )//south
{
bool found = true ;
for ( int i = 1 ; i < len ; i ++ )
{
if(word.at(i) != map.at(r+i).at(c))
{
found = false ;
break ;
}
}
if(found) {a.row = r; a.col=c ; a.dir='E';goto nextword;}
}
if(r-len >= -1 )//north
{
bool found = true ;
for ( int i = 1 ; i < len ; i ++ )
{
if(word.at(i) != map.at(r-i).at(c) )
{
found = false ;
break ;
}
}
if(found) {a.row = r; a.col=c ; a.dir='A';goto nextword;}
}
if(r-len >= -1 && c-len >= -1 )//northwest
{
bool found = true ;
for ( int i = 1 ; i < len ; i ++ )
{
if(word.at(i) != map.at(r-i).at(c-i) )
{
found = false ;
break ;
}
}
if(found){ a.row = r; a.col=c ; a.dir='H';goto nextword;}
}
if(r-len >= -1 && c+len <= cols)//northeast
{
bool found = true ;
for ( int i = 1 ; i < len ; i ++ )
{
if(word.at(i) != map.at(r-i).at(c+i))
{
found = false ;
break ;
}
}
if(found){ a.row = r; a.col=c ; a.dir='B';;goto nextword;}
}
if(r+len >= rows && c-len >=-1)//southwest
{
bool found = true ;
for ( int i = 1 ; i < len ; i ++ )
{
if(word.at(i) != map.at(r+i).at(c-i) )
{
found = false ;
break ;
}
}
if(found) {a.row = r; a.col=c ; a.dir='F';goto nextword;}
}
if(r+len <= rows && c+len <= cols)//southeast
{
bool found = true ;
for ( int i = 1 ; i < len ; i ++ )
{
if(word.at(i) != map.at(r+i).at(c+i) )
{
found = false ;
break ;
}
}
if(found){ a.row = r; a.col=c ; a.dir='D';goto nextword;}
}
}
}
}
nextword:
answers.push_back(a);
}
for ( i=0;i<answers.size();i++)
cout<<answers.at(i).row <<" "<<answers.at(i).col <<" " <<answers.at(i).dir <<endl ;
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator