重写了PrintState函数,A通过
This commit is contained in:
parent
c85d1f3049
commit
6db5438a94
|
@ -51,7 +51,7 @@ int main()
|
||||||
// 开始时公交车应该是停下的
|
// 开始时公交车应该是停下的
|
||||||
direction = BUS_STOP;
|
direction = BUS_STOP;
|
||||||
|
|
||||||
PrintState(output);
|
PrintStateInner(output);
|
||||||
ReadOutputFile(read_output, output_file);
|
ReadOutputFile(read_output, output_file);
|
||||||
if(CheckOutput(output, read_output) == BUS_FAlSE)
|
if(CheckOutput(output, read_output) == BUS_FAlSE)
|
||||||
{
|
{
|
||||||
|
@ -188,7 +188,7 @@ int main()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintState(output);
|
PrintStateInner(output);
|
||||||
ReadOutputFile(read_output, output_file);
|
ReadOutputFile(read_output, output_file);
|
||||||
if(CheckOutput(output, read_output) == BUS_FAlSE)
|
if(CheckOutput(output, read_output) == BUS_FAlSE)
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,6 +29,12 @@ int ReadInput(char* inputString);
|
||||||
* @param rails 轨道链表
|
* @param rails 轨道链表
|
||||||
* @return 返回需输出的字符串
|
* @return 返回需输出的字符串
|
||||||
*/
|
*/
|
||||||
void PrintState(char *str);
|
void PrintState();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打印当前状态的函数,供all_test使用,在oj上有问题
|
||||||
|
* @param str 需要打印的内容
|
||||||
|
*/
|
||||||
|
void PrintStateInner(char *str);
|
||||||
|
|
||||||
#endif //AUTO_PILOT_BUS_BUS_IO_H
|
#endif //AUTO_PILOT_BUS_BUS_IO_H
|
||||||
|
|
13
main.c
13
main.c
|
@ -11,10 +11,6 @@ int main()
|
||||||
* 输入的字符串
|
* 输入的字符串
|
||||||
*/
|
*/
|
||||||
char input[30];
|
char input[30];
|
||||||
/**
|
|
||||||
* 输出的字符串
|
|
||||||
*/
|
|
||||||
char output[150];
|
|
||||||
/**
|
/**
|
||||||
* the_bus指针的本体
|
* the_bus指针的本体
|
||||||
*/
|
*/
|
||||||
|
@ -39,9 +35,7 @@ int main()
|
||||||
// 开始时公交车应该是停下的
|
// 开始时公交车应该是停下的
|
||||||
direction = BUS_STOP;
|
direction = BUS_STOP;
|
||||||
|
|
||||||
PrintState(output);
|
PrintState();
|
||||||
printf("%s", output);
|
|
||||||
|
|
||||||
|
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
|
@ -163,15 +157,14 @@ int main()
|
||||||
// 这个分支只是为了符合代码规范而存在,理论上不会用到这个分支
|
// 这个分支只是为了符合代码规范而存在,理论上不会用到这个分支
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
PrintState(output);
|
PrintState();
|
||||||
printf("%s", output);
|
|
||||||
}
|
}
|
||||||
else if(result == IO_END)
|
else if(result == IO_END)
|
||||||
{
|
{
|
||||||
printf("end\n");
|
printf("end\n");
|
||||||
|
|
||||||
FreeRails(rails);
|
FreeRails(rails);
|
||||||
|
FreeQueries(queries);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
47
src/bus_io.c
47
src/bus_io.c
|
@ -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);
|
memset(str, 0, 150);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user