重写了PrintState函数,A通过

This commit is contained in:
jackfiled 2022-06-03 12:41:44 +08:00
parent c85d1f3049
commit 6db5438a94
4 changed files with 59 additions and 15 deletions

View File

@ -51,7 +51,7 @@ int main()
// 开始时公交车应该是停下的
direction = BUS_STOP;
PrintState(output);
PrintStateInner(output);
ReadOutputFile(read_output, output_file);
if(CheckOutput(output, read_output) == BUS_FAlSE)
{
@ -188,7 +188,7 @@ int main()
break;
}
PrintState(output);
PrintStateInner(output);
ReadOutputFile(read_output, output_file);
if(CheckOutput(output, read_output) == BUS_FAlSE)
{

View File

@ -29,6 +29,12 @@ int ReadInput(char* inputString);
* @param rails
* @return
*/
void PrintState(char *str);
void PrintState();
/**
* all_test使用oj上有问题
* @param str
*/
void PrintStateInner(char *str);
#endif //AUTO_PILOT_BUS_BUS_IO_H

13
main.c
View File

@ -11,10 +11,6 @@ int main()
*
*/
char input[30];
/**
*
*/
char output[150];
/**
* the_bus指针的本体
*/
@ -39,9 +35,7 @@ int main()
// 开始时公交车应该是停下的
direction = BUS_STOP;
PrintState(output);
printf("%s", output);
PrintState();
for(;;)
{
@ -163,15 +157,14 @@ int main()
// 这个分支只是为了符合代码规范而存在,理论上不会用到这个分支
break;
}
PrintState(output);
printf("%s", output);
PrintState();
}
else if(result == IO_END)
{
printf("end\n");
FreeRails(rails);
FreeQueries(queries);
break;
}
else

View File

@ -147,7 +147,52 @@ rail_node_t *ReadConfigFile()
}
}
void PrintState(char *str)
void PrintState()
{
int count, flag = 1; //flag用于标记为使下面第一个循环能够进入
rail_node_t *p = NULL;
char target[25], clockwise[25], counterclockwise[25];
for (count = 0, p = rails; flag == 1 || p != rails; p = p->next_node, count++)
{
flag=0;
target[count] = '0';
clockwise[count] = '0';
counterclockwise[count] = '0';
} //遍历轨道链表将所有站点初始化为0无任何请求
target[count] = '\0';
clockwise[count] = '\0';
counterclockwise[count] = '\0';
bus_query_t *t = NULL;
int i;
for (t = queries; t != NULL; t = t->next_node)
{
i = t->node->id - 1;
if (t->type == 0)
{
clockwise[i] = '1';
}
else if(t->type==BUS_COUNTER_CLOCK_WISE)
{
counterclockwise[i] = '1';
}
else if(t->type==BUS_TARGET)
{
target[i] = '1';
}
} //遍历请求链表将有请求的站点按照不同类型标记为1
printf("TIME:%d\n", bus_time);
printf("BUS:\n");
printf("position:%d\n", GetBusPosition());
printf("target:%s\n", target);
printf("STATION:\n");
printf("clockwise:%s\n", clockwise);
printf("counterclockwise:%s\n", counterclockwise);
}
void PrintStateInner(char *str)
{
memset(str, 0, 150);
@ -165,7 +210,7 @@ void PrintState(char *str)
target[count] = '\0';
clockwise[count] = '\0';
counterclockwise[count] = '\0';
bus_query_t *t = NULL;
int i;
for (t = queries; t != NULL; t = t->next_node)