Submission #916432

#TimeUsernameProblemLanguageResultExecution timeMemory
916432svazPatkice (COCI20_patkice)C++14
30 / 50
1 ms600 KiB
#include<bits/stdc++.h> using namespace std; int main(){ int r,s,inx,iny; cin>>r>>s; char matriz[r][s]; for(int i=0;i<r;i++){ for(int j=0;j<s;j++){ cin>>matriz[i][j]; if(matriz[i][j]=='o'){ inx=i; iny=j; } } } int x,y,cp=0,ans=(r*s)+1; char opt='Z'; x=inx; y=iny+1; cp=0; while(matriz[x][y]!='.' && matriz[x][y]!='x' && matriz[x][y]!='o' && x>=0 && x<r && y>=0 && y<s){ cp++; if(matriz[x][y]=='>')y++; if(matriz[x][y]=='<')y--; if(matriz[x][y]=='^')x--; if(matriz[x][y]=='v')x++; } if(x>=0 && x<r && y>=0 && y<s){ if(matriz[x][y]=='x'){ if(cp<ans){ ans=cp; opt='E'; } } } x=inx-1; y=iny; cp=0; while(matriz[x][y]!='.' && matriz[x][y]!='x' && matriz[x][y]!='o' && x>=0 && x<r && y>=0 && y<s){ cp++; if(matriz[x][y]=='>')y++; if(matriz[x][y]=='<')y--; if(matriz[x][y]=='^')x--; if(matriz[x][y]=='v')x++; } if(x>=0 && x<r && y>=0 && y<s){ if(matriz[x][y]=='x'){ if(cp<ans){ ans=cp; opt='N'; } if(cp==ans){ opt=min(opt,'N'); } } } x=inx+1; y=iny; cp=0; while(matriz[x][y]!='.' && matriz[x][y]!='x' && matriz[x][y]!='o' && x>=0 && x<r && y>=0 && y<s){ cp++; if(matriz[x][y]=='>')y++; if(matriz[x][y]=='<')y--; if(matriz[x][y]=='^')x--; if(matriz[x][y]=='v')x++; } if(x>=0 && x<r && y>=0 && y<s){ if(matriz[x][y]=='x'){ if(cp<ans){ ans=cp; opt='S'; } if(cp==ans){ opt=min(opt,'S'); } } } x=inx; y=iny-1; cp=0; while(matriz[x][y]!='.' && matriz[x][y]!='x' && matriz[x][y]!='o' && x>=0 && x<r && y>=0 && y<s){ cp++; if(matriz[x][y]=='>')y++; if(matriz[x][y]=='<')y--; if(matriz[x][y]=='^')x--; if(matriz[x][y]=='v')x++; } if(x>=0 && x<r && y>=0 && y<s){ if(matriz[x][y]=='x'){ if(cp<ans){ ans=cp; opt='W'; } } } if(opt=='Z')cout<<":(\n"; else{ cout<<":)\n"; cout<<opt<<"\n"; } return 0; }

Compilation message (stderr)

patkice.cpp: In function 'int main()':
patkice.cpp:57:10: warning: 'inx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   57 |         x=inx+1;
      |         ~^~~~~~
patkice.cpp:60:22: warning: 'iny' may be used uninitialized in this function [-Wmaybe-uninitialized]
   60 |     while(matriz[x][y]!='.' && matriz[x][y]!='x' && matriz[x][y]!='o' && x>=0 && x<r && y>=0 && y<s){
      |           ~~~~~~~~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...