P1518
错误信息
/tmp/compiler_fhpa16iz/src:4:17: 错误:‘int time’ redeclared as different kind of entity
4 | int ax,ay,bx,by,time;
| ^~~~
In file included from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/lib/gcc/x86_64-unknown-linux-gnu/9.3.0/include-fixed/pthread.h:32,
from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/include/c++/9.3.0/x86_64-unknown-linux-gnu/bits/gthr-default.h:35,
from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/include/c++/9.3.0/x86_64-unknown-linux-gnu/bits/gthr.h:148,
from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/include/c++/9.3.0/ext/atomicity.h:35,
from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/include/c++/9.3.0/bits/ios_base.h:39,
from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/include/c++/9.3.0/ios:42,
from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/include/c++/9.3.0/ostream:38,
from /nix/store/496xlqhx1mk41sdmrl58xi5y4pa0alys-luogu-gcc-9.3.0/include/c++/9.3.0/iostream:39,
from /tmp/compiler_fhpa16iz/src:1:
/nix/store/7rfaw11na5ajdgwr55ffzwfibbrdpk8z-glibc-2.33-56-dev/include/time.h:75:15: 附注:previous declaration ‘time_t time(time_t*)’
75 | extern time_t time (time_t *__timer) __THROW;
| ^~~~
/tmp/compiler_fhpa16iz/src: 在函数‘int work()’中:
/tmp/compiler_fhpa16iz/src:36:6: 警告:ISO C++ 不允许对类型为‘time_t (*)(time_t*) noexcept’ {aka ‘long int (*)(long int*)’}的指针自增 [-Wpointer-arith]
36 | time++;
| ^~
/tmp/compiler_fhpa16iz/src:36:6: 错误:自增操作数必须是左值
/tmp/compiler_fhpa16iz/src:38:9: 警告:‘time_t time(time_t*)’的地址永远不会为 NULL [-Waddress]
38 | cout<<time;
| ^~~~
/tmp/compiler_fhpa16iz/src:41:21: 错误:ISO C++ 不允许比较指针和整数的值 [-fpermissive]
41 | else for(int i=1;i<time;i++){
| ^~~~
/tmp/compiler_fhpa16iz/src:42:12: 错误:‘history [10000][time_t(time_t*) noexcept {aka long int(long int*)}]’用作数组下标类型无效
42 | if(a[time].x==ax&&a[time].y==ay&&a[time].fx==fxa&&b[time].x==bx&&b[time].y==by&&b[time].fx==fxb){
| ^
/tmp/compiler_fhpa16iz/src:42:27: 错误:‘history [10000][time_t(time_t*) noexcept {aka long int(long int*)}]’用作数组下标类型无效
42 | if(a[time].x==ax&&a[time].y==ay&&a[time].fx==fxa&&b[time].x==bx&&b[time].y==by&&b[time].fx==fxb){
| ^
/tmp/compiler_fhpa16iz/src:42:42: 错误:‘history [10000][time_t(time_t*) noexcept {aka long int(long int*)}]’用作数组下标类型无效
42 | if(a[time].x==ax&&a[time].y==ay&&a[time].fx==fxa&&b[time].x==bx&&b[time].y==by&&b[time].fx==fxb){
| ^
/tmp/compiler_fhpa16iz/src:42:59: 错误:‘history [10000][time_t(time_t*) noexcept {aka long int(long int*)}]’用作数组下标类型无效
42 | if(a[time].x==ax&&a[time].y==ay&&a[time].fx==fxa&&b[time].x==bx&&b[time].y==by&&b[time].fx==fxb){
| ^
/tmp/compiler_fhpa16iz/src:42:74: 错误:‘history [10000][time_t(time_t*) noexcept {aka long int(long int*)}]’用作数组下标类型无效
42 | if(a[time].x==ax&&a[time].y==ay&&a[time].fx==fxa&&b[time].x==bx&&b[time].y==by&&b[time].fx==fxb){
| ^
/tmp/compiler_fhpa16iz/src:42:89: 错误:‘history [10000][time_t(time_t*) noexcept {aka long int(long int*)}]’用作数组下标类型无效
42 | if(a[time].x==ax&&a[time].y==ay&&a[time].fx==fxa&&b[time].x==bx&&b[time].y==by&&b[time].fx==fxb){
| ^
/tmp/compiler_fhpa16iz/src:47:8: 错误:‘history [10000][time_t(time_t*) noexcept {aka long int(long int*)}]’用作数组下标类型无效
47 | a[time].x=ax,a[time].y=ay,a[time].fx=fxa;
| ^
/tmp/compiler_fhpa16iz/src:47:21: 错误:‘history [10000][time_t(time_t*) noexcept {aka long int(long int*)}]’用作数组下标类型无效
47 | a[time].x=ax,a[time].y=ay,a[time].fx=fxa;
| ^
/tmp/compiler_fhpa16iz/src:47:34: 错误:‘history [10000][time_t(time_t*) noexcept {aka long int(long int*)}]’用作数组下标类型无效
47 | a[time].x=ax,a[time].y=ay,a[time].fx=fxa;
| ^
/tmp/compiler_fhpa16iz/src:48:8: 错误:‘history [10000][time_t(time_t*) noexcept {aka long int(long int*)}]’用作数组下标类型无效
48 | b[time].x=bx,b[time].y=by,b[time].fx=fxb;
| ^
/tmp/compiler_fhpa16iz/src:48:21: 错误:‘history [10000][time_t(time_t*) noexcept {aka long int(long int*)}]’用作数组下标类型无效
48 | b[time].x=bx,b[time].y=by,b[time].fx=fxb;
| ^
/tmp/compiler_fhpa16iz/src:48:34: 错误:‘history [10000][time_t(time_t*) noexcept {aka long int(long int*)}]’用作数组下标类型无效
48 | b[time].x=bx,b[time].y=by,b[time].fx=fxb;
| ^
/tmp/compiler_fhpa16iz/src: 在函数‘int main()’中:
/tmp/compiler_fhpa16iz/src:51:2: 警告:this ‘for’ clause does not guard... [-Wmisleading-indentation]
51 | for(int i=1;i<=10;i++)dx[0][i]='*';for(int i=1;i<=10;i++)dx[11][i]='*';for(int i=1;i<=10;i++)dx[i][0]='*';for(int i=1;i<=10;i++)dx[i][11]='*';
| ^~~
/tmp/compiler_fhpa16iz/src:51:37: 附注:...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
51 | for(int i=1;i<=10;i++)dx[0][i]='*';for(int i=1;i<=10;i++)dx[11][i]='*';for(int i=1;i<=10;i++)dx[i][0]='*';for(int i=1;i<=10;i++)dx[i][11]='*';
| ^~~
/tmp/compiler_fhpa16iz/src: 在函数‘int work()’中:
/tmp/compiler_fhpa16iz/src:49:1: 警告:在有返回值的函数中,控制流程到达函数尾 [-Wreturn-type]
49 | }
| ^
代码
#include<iostream>
using namespace std;
char dx[12][12];
int ax,ay,bx,by,time;
int fxa=0,fxb=0;//AB方向
struct history{
int x,y,fx;
};
history a[10000];history b[10000];//定义结构题存贮历史数据
int work(){
if(fxa==90)if(dx[ax][ay-1]=='*')fxa=0;
else {dx[ax][ay]='.';ay--;dx[ax][ay]='F';}
else if(fxa==180)if(dx[ax+1][ay]=='*')fxa=90;
else {dx[ax][ay]='.';ax++;dx[ax][ay]='F';}
else if(fxa==270)if(dx[ax][ay+1]=='*')fxa=180;
else {dx[ax][ay]='.';ay++;dx[ax][ay]='F';}
else if(dx[ax-1][ay]=='*')fxa=270;
else {dx[ax][ay]='.';ax--;dx[ax][ay]='F';}
//F
if(fxb==90)if(dx[bx][by-1]=='*')fxb=0;
else {dx[bx][by]='.';by--;dx[bx][by]='C';}
else if(fxb==180)if(dx[bx+1][by]=='*')fxb=90;
else {dx[bx][by]='.';bx++;dx[bx][by]='C';}
else if(fxb==270)if(dx[bx][by+1]=='*')fxb=180;
else {dx[bx][by]='.';by++;dx[bx][by]='C';}
else if(dx[bx-1][by]=='*')fxb=270;
else {dx[bx][by]='.';bx--;dx[bx][by]='C';}
//K
time++;
if(ax==bx&&ay==by){
cout<<time;
return 0;
}
else for(int i=1;i<time;i++){
if(a[time].x==ax&&a[time].y==ay&&a[time].fx==fxa&&b[time].x==bx&&b[time].y==by&&b[time].fx==fxb){
cout<<"0";
return 0;
}
}
a[time].x=ax,a[time].y=ay,a[time].fx=fxa;
b[time].x=bx,b[time].y=by,b[time].fx=fxb;
}
int main(){
for(int i=1;i<=10;i++)dx[0][i]='*';for(int i=1;i<=10;i++)dx[11][i]='*';for(int i=1;i<=10;i++)dx[i][0]='*';for(int i=1;i<=10;i++)dx[i][11]='*';
//边界定义
//for(int i=0;i<=11;i++){for(int j=0;j<=11;j++)cout<<dx[i][j];cout<<endl;}
for(int i=1;i<=10;i++)for(int j=1;j<=10;j++){cin>>dx[i][j]; if(dx[i][j]=='F')ay=j,ax=i;else if(dx[i][j]=='C')by=j,bx=i;}
// cout<<ax<<" "<<ay<<" "<<bx<<" "<<by;
//i=x,j=y0
//以上为输入和AB的坐标
// cout<<ax<<" "<<ay<<" "<<bx<<" "<<by;
while(work()){
for(int i=0;i<=11;i++){for(int j=0;j<=11;j++)cout<<dx[i][j];cout<<endl;}
// cout<<ax<<" "<<ay<<" "<<bx<<" "<<by;
// int ddd;
// cin>>ddd;cout<<endl;
}
return 0;
}