diff --git a/all_test/main.c b/all_test/main.c index 775c1e7..4016eb4 100644 --- a/all_test/main.c +++ b/all_test/main.c @@ -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) { diff --git a/include/bus_io.h b/include/bus_io.h index ac29fe9..f9d6c23 100644 --- a/include/bus_io.h +++ b/include/bus_io.h @@ -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 diff --git a/main.c b/main.c index f37b1a1..9de99a7 100644 --- a/main.c +++ b/main.c @@ -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 diff --git a/src/bus_io.c b/src/bus_io.c index 407f445..2c98076 100644 --- a/src/bus_io.c +++ b/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); @@ -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)