user-0 提问: C语言中typedef 读取问题

回复:
user: user-1
content: 后续再来一个十字路口带红绿灯版？！

user: user-1
content: 闲来无事来一个动画版：//三种车 轿车 校车 卡车 速度分别3 2 1 //..........    <- row 0, 最左边进入 //.......... //.......... //^ //| //column 0,  最左边 // //第一排 输入 行 列 时间 //第二排 输入 进入时间 进入的行 车速 优先级 //优先级大的可以超车 // //例子： // //输入 //1 50 100 //2 0 1 26 //5 0 3 26 //9 0 3 26 //11 0 1 34 // //输出 // //t=0 //.................................................. //t=1 //.................................................. //t=2 //.................................................. //t=3 //1................................................. //t=4 //.1................................................ //t=5 //..1............................................... //t=6 //..31.............................................. //t=7 //...31............................................. //t=8 //....31............................................ //t=9 //.....31........................................... //t=10 //..3...31.......................................... //t=11 //.....3.31......................................... //t=12 //1......331........................................ //t=13 //.1......331....................................... //此处省略 //t=100 //.................................................. #include <stdio.h> #include <stdlib.h> #include <string.h> #include <malloc.h> #include <windows.h> #include <time.h> #include <conio.h> char *M=NULL; int *M2I=NULL; char *A=NULL; int R,C,T;//行 列 时间 char ln[40]; int t,r,v,l;//进入时间 进入的行 车速 优先级 int n,i,c,p,tt,j;  void ClearConsole() {     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);     COORD coord = {0, 0};     DWORD count;     CONSOLE_SCREEN_BUFFER_INFO csbi;      if (GetConsoleScreenBufferInfo(hStdOut, &csbi)) {         FillConsoleOutputCharacter(hStdOut, (TCHAR) 32, csbi.dwSize.X * csbi.dwSize.Y, coord, &count);         FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, csbi.dwSize.X * csbi.dwSize.Y, coord, &count);         SetConsoleCursorPosition(hStdOut, coord);     } } void ConPrintAt(int x, int y, char *CharBuffer, int len) {     DWORD count;     COORD coord = {x, y};     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);      SetConsoleCursorPosition(hStdOut, coord);     WriteConsole(hStdOut, CharBuffer, len, &count, NULL); } void HideTheCursor() {     CONSOLE_CURSOR_INFO cciCursor;     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);      if(GetConsoleCursorInfo(hStdOut, &cciCursor)) {         cciCursor.bVisible = FALSE; 		SetConsoleCursorInfo(hStdOut,	&cciCursor);     } } void ShowTheCursor() {     CONSOLE_CURSOR_INFO cciCursor;     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);      if (GetConsoleCursorInfo(hStdOut, &cciCursor)) {         cciCursor.bVisible = TRUE; 		SetConsoleCursorInfo(hStdOut,	&cciCursor);     } } int main(int argc,char **argv) {     if (argc==1) {         fgets(ln,40,stdin);         if (3!=sscanf(ln,"%d%d%d",&R,&C,&T)) return 1;         if (!(R>0 && C>0 && T>0)) return 1;     } else {         ClearConsole();         HideTheCursor();         srand(time(NULL));         R=1+rand()%6;         C=20+rand()%10*10;         T=C+20;     }     n=0;     while (1) {         if (argc==1) {             fgets(ln,40,stdin);             if (ln[0]=='\n') break;         } else {             if (0==rand()%(R*5) && n>R*3) {                 break;             } else {                 sprintf(ln,"%d %d %d %d\n",rand()%20,rand()%R,1+rand()%3,rand()%(R*3));             }         }         if (4!=sscanf(ln,"%d%d%d%d",&t,&r,&v,&l)) return 1;         if (!(0<=t && t<=T && r<R && 1<=v && v<=3 && 0<=l)) return 1;         A=(char *)realloc(A,(n+1)*5*sizeof(int));         A[n*5+0]=t;         A[n*5+1]=r;         A[n*5+2]=v;         A[n*5+3]=l;         A[n*5+4]=-2;//第n辆车的初始位置         n++;     }     M=(char *)malloc(R*C*sizeof(char));     M2I=(int *)malloc(R*(C+3)*sizeof(int));     for (tt=0;tt<=T;tt++) {         memset(M,'.',R*C*sizeof(char));         for (i=0;i<R*(C+3);i++) M2I[i]=n;//标记所有位置无车         if (argc==1) printf("t=%d\n",tt);         for (i=0;i<n;i++) {//第i辆车             t=A[i*5+0];             r=A[i*5+1];             v=A[i*5+2];             l=A[i*5+3];             p=A[i*5+4];             if (p==-2) {                 if (tt==t) p=-1;//到进入时间了             } else if (-1<=p && p<C) {                 for (c=0;c<v;c++) {                     if (M2I[r*(C+3)+p+1+c]<n) {//前面有别的车                         j=M2I[r*(C+3)+p+1+c];                         if (l<=A[j*5+3]) break; //前车的优先级≥我的优先级                     }                 }                 p+=c;                 if (0<=p && p<C+3) M2I[r*(C+3)+p]=i;             }             A[i*5+4]=p;             if (0<=p && p<C) M[r*C+p]='0'+v;         }         if (argc==1) {             for (r=0;r<R;r++) {                 printf("%.*s\n",C,M+r*C);             }         } else {             for (r=0;r<R;r++) {                 ConPrintAt(0,r,M+r*C,C);             }             Sleep(200);             if (kbhit()) {getch();break;}         }     }     free(M2I);     free(M);     free(A);      if (argc!=1) ShowTheCursor();     return 0; } //输入： //1 50 100 //2 0 1 26 //5 0 3 26 //9 0 3 26 //11 0 1 34 // //输出： //t=0 //.................................................. //t=1 //.................................................. //t=2 //.................................................. //t=3 //1................................................. //t=4 //.1................................................ //t=5 //..1............................................... //t=6 //..31.............................................. //t=7 //...31............................................. //t=8 //....31............................................ //t=9 //.....31........................................... //t=10 //..3...31.......................................... //t=11 //.....3.31......................................... //t=12 //1......331........................................ //t=13 //.1......331....................................... //t=14 //..1......331...................................... //t=15 //...1......331..................................... //t=16 //....1......331.................................... //t=17 //.....1......331................................... //t=18 //......1......331.................................. //t=19 //.......1......331................................. //t=20 //........1......331................................ //t=21 //.........1......331............................... //t=22 //..........1......331.............................. //t=23 //...........1......331............................. //t=24 //............1......331............................ //t=25 //.............1......331........................... //t=26 //..............1......331.......................... //t=27 //...............1......331......................... //t=28 //................1......331........................ //t=29 //.................1......331....................... //t=30 //..................1......331...................... //t=31 //...................1......331..................... //t=32 //....................1......331.................... //t=33 //.....................1......331................... //t=34 //......................1......331.................. //t=35 //.......................1......331................. //t=36 //........................1......331................ //t=37 //.........................1......331............... //t=38 //..........................1......331.............. //t=39 //...........................1......331............. //t=40 //............................1......331............ //t=41 //.............................1......331........... //t=42 //..............................1......331.......... //t=43 //...............................1......331......... //t=44 //................................1......331........ //t=45 //.................................1......331....... //t=46 //..................................1......331...... //t=47 //...................................1......331..... //t=48 //....................................1......331.... //t=49 //.....................................1......331... //t=50 //......................................1......331.. //t=51 //.......................................1......331. //t=52 //........................................1......331 //t=53 //.........................................1......33 //t=54 //..........................................1....... //t=55 //...........................................1...... //t=56 //............................................1..... //t=57 //.............................................1.... //t=58 //..............................................1... //t=59 //...............................................1.. //t=60 //................................................1. //t=61 //.................................................1 //t=62 …… //t=100 //.................................................. // //★运行时随便带一个命令行参数可动画演示！★

user: user-2
content: 来学习学习

user: user-0
content: 顶一一一一一一下

user: user-1
content: 给出的例子的输出都无法自圆其说。

user: user-1
content: 跟year、mon、day没半毛钱关系。

user: user-3
content: main函数里定义重名变量，这是不可以的，自己看着都糊涂了

user: user-0
content: 不是。。。是我的锅 没有表达清楚 大神你先看看题  一楼只是举例 创建行列式 各种车进入的时间 都是键盘输入读取的 而且各种车速也不一样 还有超车和优先级问题

user: user-4
content: 这根typedef 有半毛钱关系。。。   	char buff[20]; 	memset(buff, '.', sizeof(buff));  	char str[21] = { 0 };  	for (int i = 0; i < 30; i++) 	{ 		if (i == 3 || 			i == 4 || 			i == 5 || 			i == 10 || 			i == 11 || 			i == 12) 		{ 			buff[0] = '1'; 		} 		else 		{ 			buff[0] = '.'; 		}  		memcpy(str, buff, sizeof(buff));  		printf("t = %2d : %s\n", i, str);  		memcpy(buff + 1, str, sizeof(buff)-sizeof(char)); 	}

user: user-0
content: 三种车 轿车 校车 卡车 速度分别3 2 1 ..........    <- row 0, 最左边进入 .......... .......... ^ | column 0,  最左边  第一排 输入 行 列 时间 第二排 输入 进入时间 进入的行 车速 优先级 优先级大的可以超车  例子： 输入 1 50 100  2 0 1 26 5 0 3 26 9 0 3 26 11 0 1 34 14 0 1 17 30 0 2 26 45 0 3 27 50 0 1 28 60 0 2 28 75 0 3 27 80 0 1 26  输出  t=0 .................................................. t=1 .................................................. t=2 .................................................. t=3 1................................................. t=4 ...1.............................................. t=5 ......1........................................... t=6 3........1........................................ t=7 ..3.........1..................................... t=8 ....3..........1.................................. t=9 ......3...........1............................... t=10 3.......3............1............................ t=11 ..3.......3.............1......................... t=12 1...3.......3..............1...................... t=13 ...1..3.......3...............1................... t=14 .....1..3.......3................1................ t=15 1......1..3.......3.................1............. t=16 ...1.....1..3.......3..................1.......... t=17 ......1....1..3.......3...................1....... t=18 .........1...1..3.......3....................1.... t=19 ............1..1..3.......3.....................1. t=20 ...............1.1..3.......3..................... t=21 ..................11..3.......3................... t=22 ....................11..3.......3................. t=23 ......................11..3.......3............... t=24 ........................11..3.......3............. t=25 ..........................11..3.......3........... t=26 ............................11..3.......3......... t=27 ..............................11..3.......3....... t=28 ................................11..3.......3..... t=29 ..................................11..3.......3... t=30 ....................................11..3.......3. t=31 2.....................................11..3....... t=32 .2......................................11..3..... t=33 ..2.......................................11..3... t=34 ...2........................................11..3. t=35 ....2.........................................11.. t=36 .....2...........................................1 t=37 ......2........................................... t=38 .......2.......................................... t=39 ........2......................................... t=40 .........2........................................ t=41 ..........2....................................... t=42 ...........2...................................... t=43 ............2..................................... t=44 .............2.................................... t=45 ..............2................................... t=46 3..............2.................................. t=47 ..3.............2................................. t=48 ....3............2................................ t=49 ......3...........2............................... t=50 ........3..........2.............................. t=51 1.........3.........2............................. t=52 ...1........3........2............................ t=53 ......1.......3.......2........................... t=54 .........1......3......2.......................... t=55 ............1.....3.....2......................... t=56 ...............1....3....2........................ t=57 ..................1...3...2....................... t=58 .....................1..3..2...................... t=59 .......................1..3.2..................... t=60 .........................1.3.2.................... t=61 2.........................1.3.2................... t=62 .2.........................1.3.2.................. t=63 ..2.........................1.3.2................. t=64 ...2.........................1.3.2................ t=65 ....2.........................1.3.2............... t=66 .....2.........................1.3.2.............. t=67 ......2.........................1.3.2............. t=68 .......2.........................1.3.2............ t=69 ........2.........................1.3.2........... t=70 .........2.........................1.3.2.......... t=71 ..........2.........................1.3.2......... t=72 ...........2.........................1.3.2........ t=73 ............2.........................1.3.2....... t=74 .............2.........................1.3.2...... t=75 ..............2.........................1.3.2..... t=76 3..............2.........................1.3.2.... t=77 ..3.............2.........................1.3.2... t=78 ....3............2.........................1.3.2.. t=79 ......3...........2.........................1.3.2. t=80 ........3..........2.........................1.3.2 t=81 1.........3.........2.........................1.3. t=82 ...1........3........2.........................1.. t=83 ......1.......3.......2........................... t=84 .........1......3......2.......................... t=85 ............1.....3.....2......................... t=86 ...............1....3....2........................ t=87 ..................1...3...2....................... t=88 .....................1..3..2...................... t=89 ........................1.3.2..................... t=90 ...........................132.................... t=91 ............................132................... t=92 .............................132.................. t=93 ..............................132................. t=94 ...............................132................ t=95 ................................132............... t=96 .................................132.............. t=97 ..................................132............. t=98 ...................................132............ t=99 ....................................132........... t=100 .....................................132..........   例子 输入 5 10 20 0 1 2 15  0 3 2 14  0 4 1 34 2 4 1 7  4 3 2 18  4 4 2 24  6 3 1 11  6 4  1 8  10 0 2 40  10 1 1 23  12 2 3 11  12 4 2 34  18 1 1 3   输出 .........2 ...1...... .......... .......... .......2..

user: user-1
content: 楼主给的代码太少，图片表示啥意思描述也太少。

user: user-0
content: 求大腿告知 用C语言写结构体typedef 怎么输出打印下面那张图片

user: user-1
content: 楼主语文稍差，不知所云。 仅供参考：//char (*(*x[3])())[5];//x是什么类型的变量? // //分析C语言声明，关键是搞清楚这个变量是个什么东西（函数、指针、数组）， //是函数那么剩下的就是他的参数和返回值， //是指针那剩下部分是说明他指向什么， //是数组剩下的部分就是说明数组的成员是什么类型。 //解析C语言声明规则： //从左侧第一个标识符开始，按照优先级进行结合。*表示是..的指针，const表示只读的，volatile表示可变的，[]表示是数组，()表示是函数。 // //x和[3]结合说明是一个大小为3的数组，该数组的每个元素为一类指针，该类指针指向一类函数，该类函数无参数，返回一类指针，该类指针指向一个大小为5的char型数组 #include <stdio.h> #include <typeinfo.h> char num[5]; char (*x00())[5] {     return # } int main() {     char (*(*x[3])())[5];//是个数组，大小为3     char (*(*x0  )())[5];//数组的元素，是个函数指针     char (*( x00 )())[5];//函数原型，参数为空，返回值为指针     char (*  x000   )[5];//返回值      x0 = x00;     x[0] = x0;     x[1] = x0;     x[2] = x0;     printf("typeid(x).name() is %s\n",typeid(x).name());     return 0; } //typeid(x).name() is char (* (__cdecl**)(void))[5]

user: user-0
content: #include <stdio.h> #include <stdlib.h> #include <string.h>   struct highWay {     int nrow;     int ncol;     char** stateSim; };  //不会写 void movement(struct highWay *simHW, int speed,int priority) {     int i, j;     for (i = 0;i < simHW->nrow;i++)     {         for (j = 0; j < simHW->ncol - 1;j--)         {             if (simHW->stateSim[i][j] == 1)             {                 simHW->stateSim[i][j] = 0;                 if (j != simHW->ncol - 1)                 {                     simHW->stateSim[i][j + 1] = 1;                 }             }         }     }      }  void arrival(int arriveRow, struct highWay *simHW) {     simHW->stateSim[arriveRow][0] = 1; }  void showHighWay(struct highWay* simHW) {     int i, j;     for (i = 0;i < simHW->nrow;i++)     {         for (j = 0; j < simHW->ncol; j++)         {             if (simHW->stateSim[i][j] == 0)             {                 printf(".");             }         }     } }  void highwaySimulate(int nstep, int arriveRow, struct highWay* simHW,int speed,int priority) {     int i;     for (i = 0; i < nstep; i++)     {         movement(simHW,speed,priority);     }     arrival(arriveRow, simHW); }  int main() {     struct highWay simHighWay;     int nrow, ncol, time;     int i, inTime, lastTime,speed,priority;     int arriveRow;          while (scanf("%d %d %d",&simHighWay.nrow, &simHighWay.ncol, &time)!=EOF)     {         getchar();         nrow = simHighWay.nrow;         ncol = simHighWay.ncol;                  simHighWay.stateSim = (char**)malloc(sizeof(char*)*nrow);         for (i = 0; i < nrow; i++)         {             simHighWay.stateSim[i] = (char*)malloc(sizeof(char)*ncol);             memset(simHighWay.stateSim[i], 0, sizeof(char)*ncol);         }                  lastTime = 0;         scanf("%d %d %d %d", &inTime, &arriveRow,&speed,&priority);                      getchar();             if (inTime < time && inTime >= lastTime)             {             highwaySimulate(inTime - lastTime, arriveRow, &simHighWay,speed,priority);             }                           for (i = lastTime; i < time - 1; i++)         {             movement(&simHighWay,speed,priority);         }                  showHighWay(&simHighWay);                 printf("\n");                  for (i = 0;i < nrow;i++)         {             free(simHighWay.stateSim[i]);         }         free(simHighWay.stateSim);     }     return 0; }   请问哪里写错了

user: user-1
content: 改正一处bug第106行：//三种车 轿车 校车 卡车 速度分别3 2 1 //..........    <- row 0, 最左边进入 //.......... //.......... //^ //| //column 0,  最左边 // //第一排 输入 行 列 时间 //第二排 输入 进入时间 进入的行 车速 优先级 //优先级大的可以超车 // //例子： // //输入 //1 50 100 //2 0 1 26 //5 0 3 26 //9 0 3 26 //11 0 1 34 // //输出 // //t=0 //.................................................. //t=1 //.................................................. //t=2 //.................................................. //t=3 //1................................................. //t=4 //.1................................................ //t=5 //..1............................................... //t=6 //..31.............................................. //t=7 //...31............................................. //t=8 //....31............................................ //t=9 //.....31........................................... //t=10 //..3...31.......................................... //t=11 //.....3.31......................................... //t=12 //1......331........................................ //t=13 //.1......331....................................... //此处省略 //t=100 //.................................................. #include <stdio.h> #include <stdlib.h> #include <string.h> #include <malloc.h> char *M=NULL; int *M2I=NULL; char *A=NULL; int R,C,T;//行 列 时间 char ln[40]; int t,r,v,l;//进入时间 进入的行 车速 优先级 int n,i,c,p,tt,j; int main() {     fgets(ln,40,stdin);     if (3!=sscanf(ln,"%d%d%d",&R,&C,&T)) return 1;     if (!(R>0 && C>0 && T>0)) return 1;     n=0;     while (1) {         fgets(ln,40,stdin);         if (ln[0]=='\n') break;         if (4!=sscanf(ln,"%d%d%d%d",&t,&r,&v,&l)) return 1;         if (!(0<=t && t<=T && r<R && 1<=v && v<=3 && 0<=l)) return 1;         A=(char *)realloc(A,(n+1)*5*sizeof(int));         A[n*5+0]=t;         A[n*5+1]=r;         A[n*5+2]=v;         A[n*5+3]=l;         A[n*5+4]=-2;//第n辆车的初始位置         n++;     }     M=(char *)malloc(R*C*sizeof(char));     M2I=(int *)malloc(R*(C+3)*sizeof(int));     for (tt=0;tt<=T;tt++) {         memset(M,'.',R*C*sizeof(char));         for (i=0;i<R*(C+3);i++) M2I[i]=n;//标记所有位置无车         printf("t=%d\n",tt);         for (i=0;i<n;i++) {//第i辆车             t=A[i*5+0];             r=A[i*5+1];             v=A[i*5+2];             l=A[i*5+3];             p=A[i*5+4];             if (p==-2) {                 if (tt==t) p=-1;//到进入时间了             } else if (-1<=p && p<C) {                 for (c=0;c<v;c++) {                     if (M2I[r*(C+3)+p+1+c]<n) {//前面有别的车                         j=M2I[r*(C+3)+p+1+c];                         if (l<=A[j*5+3]) break; //前车的优先级≥我的优先级                     }                 }                 p+=c;                 if (0<=p && p<C+3) M2I[r*(C+3)+p]=i;             }             A[i*5+4]=p;             if (0<=p && p<C) M[r*C+p]='0'+v;         }         for (r=0;r<R;r++) {             printf("%.*s\n",C,M+r*C);         }     }     free(M2I);     free(M);     free(A);     return 0; } //输入： //1 50 100 //2 0 1 26 //5 0 3 26 //9 0 3 26 //11 0 1 34 // //输出： //t=0 //.................................................. //t=1 //.................................................. //t=2 //.................................................. //t=3 //1................................................. //t=4 //.1................................................ //t=5 //..1............................................... //t=6 //..31.............................................. //t=7 //...31............................................. //t=8 //....31............................................ //t=9 //.....31........................................... //t=10 //..3...31.......................................... //t=11 //.....3.31......................................... //t=12 //1......331........................................ //t=13 //.1......331....................................... //t=14 //..1......331...................................... //t=15 //...1......331..................................... //t=16 //....1......331.................................... //t=17 //.....1......331................................... //t=18 //......1......331.................................. //t=19 //.......1......331................................. //t=20 //........1......331................................ //t=21 //.........1......331............................... //t=22 //..........1......331.............................. //t=23 //...........1......331............................. //t=24 //............1......331............................ //t=25 //.............1......331........................... //t=26 //..............1......331.......................... //t=27 //...............1......331......................... //t=28 //................1......331........................ //t=29 //.................1......331....................... //t=30 //..................1......331...................... //t=31 //...................1......331..................... //t=32 //....................1......331.................... //t=33 //.....................1......331................... //t=34 //......................1......331.................. //t=35 //.......................1......331................. //t=36 //........................1......331................ //t=37 //.........................1......331............... //t=38 //..........................1......331.............. //t=39 //...........................1......331............. //t=40 //............................1......331............ //t=41 //.............................1......331........... //t=42 //..............................1......331.......... //t=43 //...............................1......331......... //t=44 //................................1......331........ //t=45 //.................................1......331....... //t=46 //..................................1......331...... //t=47 //...................................1......331..... //t=48 //....................................1......331.... //t=49 //.....................................1......331... //t=50 //......................................1......331.. //t=51 //.......................................1......331. //t=52 //........................................1......331 //t=53 //.........................................1......33 //t=54 //..........................................1....... //t=55 //...........................................1...... //t=56 //............................................1..... //t=57 //.............................................1.... //t=58 //..............................................1... //t=59 //...............................................1.. //t=60 //................................................1. //t=61 //.................................................1 //t=62 //.................................................. //t=63 //.................................................. //t=64 //.................................................. //t=65 //.................................................. //t=66 //.................................................. //t=67 //.................................................. //t=68 //.................................................. //t=69 //.................................................. //t=70 //.................................................. //t=71 //.................................................. //t=72 //.................................................. //t=73 //.................................................. //t=74 //.................................................. //t=75 //.................................................. //t=76 //.................................................. //t=77 //.................................................. //t=78 //.................................................. //t=79 //.................................................. //t=80 //.................................................. //t=81 //.................................................. //t=82 //.................................................. //t=83 //.................................................. //t=84 //.................................................. //t=85 //.................................................. //t=86 //.................................................. //t=87 //.................................................. //t=88 //.................................................. //t=89 //.................................................. //t=90 //.................................................. //t=91 //.................................................. //t=92 //.................................................. //t=93 //.................................................. //t=94 //.................................................. //t=95 //.................................................. //t=96 //.................................................. //t=97 //.................................................. //t=98 //.................................................. //t=99 //.................................................. //t=100 //.................................................. //

user: user-0
content: 感谢老师耐心回复

user: user-5
content: 不知所淫

user: user-1
content: 不一定对，仅供参考： //三种车 轿车 校车 卡车 速度分别3 2 1 //..........    <- row 0, 最左边进入 //.......... //.......... //^ //| //column 0,  最左边 // //第一排 输入 行 列 时间 //第二排 输入 进入时间 进入的行 车速 优先级 //优先级大的可以超车 // //例子： // //输入 //1 50 100 //2 0 1 26 //5 0 3 26 //9 0 3 26 //11 0 1 34 // //输出 // //t=0 //.................................................. //t=1 //.................................................. //t=2 //.................................................. //t=3 //1................................................. //t=4 //.1................................................ //t=5 //..1............................................... //t=6 //..31.............................................. //t=7 //...31............................................. //t=8 //....31............................................ //t=9 //.....31........................................... //t=10 //..3...31.......................................... //t=11 //.......31......................................... //t=12 //1.......31........................................ //此处省略 //t=100 //.................................................. #include <stdio.h> #include <stdlib.h> #include <string.h> #include <malloc.h> char *M=NULL; int *M2I=NULL; char *A=NULL; int R,C,T;//行 列 时间 char ln[40]; int t,r,v,l;//进入时间 进入的行 车速 优先级 int n,i,c,p,tt,j; int main() {     fgets(ln,40,stdin);     if (3!=sscanf(ln,"%d%d%d",&R,&C,&T)) return 1;     if (!(R>0 && C>0 && T>0)) return 1;     n=0;     while (1) {         fgets(ln,40,stdin);         if (ln[0]=='\n') break;         if (4!=sscanf(ln,"%d%d%d%d",&t,&r,&v,&l)) return 1;         if (!(0<=t && t<=T && r<R && 1<=v && v<=3 && 0<=l)) return 1;         A=(char *)realloc(A,(n+1)*5*sizeof(int));         A[n*5+0]=t;         A[n*5+1]=r;         A[n*5+2]=v;         A[n*5+3]=l;         A[n*5+4]=-2;//第n辆车的初始位置         n++;     }     M=(char *)malloc(R*C*sizeof(char));     M2I=(int *)malloc(R*(C+3)*sizeof(int));     for (tt=0;tt<=T;tt++) {         memset(M,'.',R*C*sizeof(char));         for (i=0;i<R*(C+3);i++) M2I[i]=n;//标记所有位置无车         printf("t=%d\n",tt);         for (i=0;i<n;i++) {//第i辆车             t=A[i*5+0];             r=A[i*5+1];             v=A[i*5+2];             l=A[i*5+3];             p=A[i*5+4];             if (p==-2) {                 if (tt==t) p=-1;//到进入时间了             } else if (-1<=p && p<C) {                 for (c=0;c<v;c++) {                     if (M2I[r*(C+3)+p+1+c]<n) {//前面有别的车                         j=M2I[r*(C+3)+p+1+c];                         if (l<=A[j*5+3]) break; //前车的优先级≥我的优先级                     }                 }                 p+=c;                 M2I[r*(C+3)+p]=i;             }             A[i*5+4]=p;             if (0<=p && p<C) M[r*C+p]='0'+v;         }         for (r=0;r<R;r++) {             printf("%.*s\n",C,M+r*C);         }     }     free(M2I);     free(M);     free(A);     return 0; } //输入： //1 50 100 //2 0 1 26 //5 0 3 26 //9 0 3 26 //11 0 1 34 // //输出： //t=0 //.................................................. //t=1 //.................................................. //t=2 //.................................................. //t=3 //1................................................. //t=4 //.1................................................ //t=5 //..1............................................... //t=6 //..31.............................................. //t=7 //...31............................................. //t=8 //....31............................................ //t=9 //.....31........................................... //t=10 //..3...31.......................................... //t=11 //.....3.31......................................... //t=12 //1......331........................................ //t=13 //.1......331....................................... //t=14 //..1......331...................................... //t=15 //...1......331..................................... //t=16 //....1......331.................................... //t=17 //.....1......331................................... //t=18 //......1......331.................................. //t=19 //.......1......331................................. //t=20 //........1......331................................ //t=21 //.........1......331............................... //t=22 //..........1......331.............................. //t=23 //...........1......331............................. //t=24 //............1......331............................ //t=25 //.............1......331........................... //t=26 //..............1......331.......................... //t=27 //...............1......331......................... //t=28 //................1......331........................ //t=29 //.................1......331....................... //t=30 //..................1......331...................... //t=31 //...................1......331..................... //t=32 //....................1......331.................... //t=33 //.....................1......331................... //t=34 //......................1......331.................. //t=35 //.......................1......331................. //t=36 //........................1......331................ //t=37 //.........................1......331............... //t=38 //..........................1......331.............. //t=39 //...........................1......331............. //t=40 //............................1......331............ //t=41 //.............................1......331........... //t=42 //..............................1......331.......... //t=43 //...............................1......331......... //t=44 //................................1......331........ //t=45 //.................................1......331....... //t=46 //..................................1......331...... //t=47 //...................................1......331..... //t=48 //....................................1......331.... //t=49 //.....................................1......331... //t=50 //......................................1......331.. //t=51 //.......................................1......331. //t=52 //........................................1......331 //t=53 //.........................................1......33 //t=54 //..........................................1....... //t=55 //...........................................1...... //t=56 //............................................1..... //t=57 //.............................................1.... //t=58 //..............................................1... //t=59 //...............................................1.. //t=60 //................................................1. //t=61 //.................................................1 //t=62 //.................................................. //t=63 //.................................................. //t=64 //.................................................. //t=65 //.................................................. //t=66 //.................................................. //t=67 //.................................................. //t=68 //.................................................. //t=69 //.................................................. //t=70 //.................................................. //t=71 //.................................................. //t=72 //.................................................. //t=73 //.................................................. //t=74 //.................................................. //t=75 //.................................................. //t=76 //.................................................. //t=77 //.................................................. //t=78 //.................................................. //t=79 //.................................................. //t=80 //.................................................. //t=81 //.................................................. //t=82 //.................................................. //t=83 //.................................................. //t=84 //.................................................. //t=85 //.................................................. //t=86 //.................................................. //t=87 //.................................................. //t=88 //.................................................. //t=89 //.................................................. //t=90 //.................................................. //t=91 //.................................................. //t=92 //.................................................. //t=93 //.................................................. //t=94 //.................................................. //t=95 //.................................................. //t=96 //.................................................. //t=97 //.................................................. //t=98 //.................................................. //t=99 //.................................................. //t=100 //.................................................. //

user: user-0
content: 求大神们给个思路

user: user-0
content: 这个是两个问题  第一个是想弄清楚指针问题 是怎么传递的  第二个是关于C语言的程序 希望可以给一个借鉴的代码 以便更好理解指针