文件操作练习。注意B题的读取不能用struct。
D和谐词汇的题,输入是若干字符串,不以空行结束. 所以 gets(line); while (line[0]){... gets(line);}就会导致时间超限,代码在等空行,但in数据没有。应改为while(gets(line))。
/*文件练习B题. 读取一个包含7类数据的二进制文件,找到指定部分内容,并正确解释输出。
思路分析:主体框架是读取二进制文件, while (fread(buffer, buffLen, 1, infile) > 0){...}
因为二进制文件的记录长度是固定的,所以可以计算每条记录的长度,使用fseek直接定位到指定段;
所以用fseek的话,实际只需要读一次就可以。
但是这道题的特殊之处在于,一条记录内是顺序包含7种类型数据,是分多次写入,因此带来的麻烦是
虽然每段内容结构相同,但不能用struct进行整块读取。
因为struct的成员之间有内存空隙;除非源文件本身是用struct格式写入才行。
经测试,struct {含7种变量和数组}的长度为200, 但实际7种变量和数组的总长要小一些.
因此,可以直接定位,但必须分别读取,写出的代码冗长,且容易在变量名和输出格式上出错。
一种办法是:按总长度整块读取到字节数组中,然后再逐个定义对应类型的指针,按间接访问就可格式化解释输出。
例: char buffer[LEN];
int i=0; printf("%c\n", buffer[i]); i++;
short * hdPtr=&buffer[i]; printf("%hd\n", *hdPtr); i+=sizeof(short);
*/
RunID | User | Nick Name | Problem ID | Result | Memory | Time | Language | Code Length | Submit Time |
102451 | 2022212922 | sherry | Wrong Answer | 1192KB | 14ms | C | 1642 bytes | 2023-05-04 23:54:16 | |
102432 | 2022212922 | sherry | Wrong Answer | 1192KB | 12ms | C | 1499 bytes | 2023-05-04 23:44:07 | |
102428 | 2022212922 | sherry | Compile Error | 0KB | 0ms | C | 1495 bytes | 2023-05-04 23:42:32 | |
102422 | 2022212922 | sherry | *Accepted101846 | 1192KB | 9ms | C | 2082 bytes | 2023-05-04 23:38:58 | |
102416 | 2022212922 | sherry | Wrong Answer | 1192KB | 9ms | C | 1469 bytes | 2023-05-04 23:37:35 | |
102413 | 2022212922 | sherry | *Accepted65107 | 1192KB | 13ms | C | 2347 bytes | 2023-05-04 23:36:51 | |
102401 | 2022212922 | sherry | Wrong Answer | 1192KB | 11ms | C | 1469 bytes | 2023-05-04 23:30:22 | |
102374 | 2022212922 | sherry | *Accepted64826 | 1192KB | 11ms | C | 1481 bytes | 2023-05-04 23:20:46 | |
102367 | 2022212922 | sherry | *Accepted64826 | 1192KB | 11ms | C | 1507 bytes | 2023-05-04 23:19:30 | |
102345 | 2022212922 | sherry | Wrong Answer | 1192KB | 10ms | C | 1518 bytes | 2023-05-04 23:09:41 | |
102309 | 2022212922 | sherry | Wrong Answer | 1192KB | 11ms | C | 1526 bytes | 2023-05-04 22:45:37 | |
102305 | 2022212922 | sherry | Wrong Answer | 1192KB | 10ms | C | 1515 bytes | 2023-05-04 22:44:56 | |
102299 | 2022212922 | sherry | Wrong Answer | 1192KB | 9ms | C | 1578 bytes | 2023-05-04 22:39:54 | |
102291 | 2022212922 | sherry | Time Limit Exceed | 1068KB | 8815ms | C | 1503 bytes | 2023-05-04 22:35:39 | |
102239 | 2022212922 | sherry | Wrong Answer | 1192KB | 11ms | C | 1387 bytes | 2023-05-04 22:00:20 | |
102098 | 2022212922 | sherry | Output Limit Exceed | 1192KB | 12ms | C | 1404 bytes | 2023-05-04 20:02:22 | |
102040 | 2022212922 | sherry | Wrong Answer | 1192KB | 11ms | C | 1576 bytes | 2023-05-04 17:43:27 | |
102037 | 2022212922 | sherry | Wrong Answer | 1192KB | 9ms | C | 1501 bytes | 2023-05-04 17:38:24 | |
90352 | 2022212922 | sherry | Accepted | 1192KB | 12ms | C | 1772 bytes | 2023-04-17 23:00:55 |