原文发布于Hibiki33’s Blog,转载请标明出处。
代码仅供参考,查重结果自负。
1. 五子棋危险判断
【问题描述】
已知两人分别执白棋和黑棋在一个围棋棋盘上下五子棋,若同一颜色的棋子在同一条横行、纵行或斜线上连成5个棋子,则执该颜色棋子的人获胜。编写程序读入某一时刻下棋的状态,并判断是否有人即将获胜,即:同一颜色的棋子在同一条横行、纵列或斜线上连成4个棋子,且该4个棋子的两端至少有一端为空位置。
输入的棋盘大小是19×19,用数字0表示空位置(即没有棋子),用数字1表示该位置下了一白色棋子,用数字2表示该位置下了一黑色棋子。假设同一颜色的棋子在同一条横行、纵列或斜线上连成的棋子个数不会超过4个,并且最多有一人连成线的棋子个数为4。
【输入形式】
从控制台输入用来表示棋盘状态的数字0、1或2;每行输入19个数字,各数字之间以一个空格分隔,每行最后一个数字后没有空格;共输入19行表示棋盘状态的数字。
【输出形式】
若有人即将获胜,则先输出即将获胜人的棋子颜色(1表示白色棋子,2表示黑色棋子),然后输出英文冒号:,最后输出连成4个棋子连线的起始位置(棋盘横行自上往下、纵列自左往右从1开始计数,横行最小的棋子在棋盘上的横行数和纵列数作为连线的起始位置,若在同一行上,则纵列数最小的棋子位置作为起始位置,两数字之间以一个英文逗号,作为分隔符)。
若没有人获胜,则输出英文字符串:No。
无论输出什么结果,最后都要有回车换行符。
【输入样例1】
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 2 0 1 1 2 0 0 0 0 0 0 0
0 0 0 0 0 2 1 1 1 1 2 2 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 2 1 2 0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 1 0 2 2 0 0 0 0 0 0 0 0
0 0 0 0 0 2 0 1 0 0 2 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 1 2 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
【输出样例1】
1:9,8
【输入样例2】
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 2 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 2 2 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
【输出样例2】
No
【样例说明】
在输入的样例1中,执白棋(数字1表示)的人即将获胜,连成4个棋子且有一端为空的起始位置在第9行第8列,所以输出1:9,8。
在输入的样例2中,还没有同一颜色的棋子连成4个,所以无人即将获胜,直接输出No。
【评分标准】
该题要求判断五子棋的棋盘状态,提交程序文件名为chess.c。
【参考答案】
对每个点遍历8 / 2 = 4个方向,注意别越界即可。我这里将棋盘外面包了一圈-1,在判断连续4子两侧的0时能方便点。
这题评测机上的测试点特别弱,代码哪怕交上去是对的很可能也是有bug的,建议自己多测试测试。
#include <stdio.h>
#include <stdlib.h>
int grid[25][25];
int quat_equal(int a, int b, int c, int d)
{
if (a == b && a == c && a == d)
{
return 1;
}
return 0;
}
int main()
{
for (int i = 1; i <= 19; i++)
{
for (int j = 1; j <= 19; j++)
{
scanf("%d", &grid[i][j]);
}
}
for (int i = 0; i <= 20; i++)
{
grid[20][i] = grid[i][20] = -1;
grid[0][i] = grid[i][0] = -1;
}
for (int i = 1; i <= 19; i++)
{
for (int j = 1; j <= 19; j++)
{
if (grid[i][j])
{
if (j <= 16)
{
if (quat_equal(grid[i][j], grid[i][j + 1], grid[i][j + 2], grid[i][j + 3]))
{
if (!grid[i][j - 1] || !grid[i][j + 4]) {
printf("%d:%d,%d", grid[i][j], i, j);
return 0;
}
}
}
if (i <= 16)
{
if (quat_equal(grid[i][j], grid[i + 1][j], grid[i + 2][j], grid[i + 3][j]))
{
if (!grid[i - 1][j] || !grid[i + 4][j]) {
printf("%d:%d,%d", grid[i][j], i, j);
return 0;
}
}
}
if (i <= 16 && j <= 16)
{
if (quat_equal(grid[i][j], grid[i + 1][j + 1], grid[i + 2][j + 2], grid[i + 3][j + 3]))
{
if (!grid[i - 1][j - 1] || !grid[i + 4][j + 4]) {
printf("%d:%d,%d", grid[i][j], i, j);
return 0;
}
}
}
if (j >= 4) {
if (quat_equal(grid[i][j], grid[i + 1][j - 1], grid[i + 2][j - 2], grid[i + 3][j - 3]))
{
if (!grid[i - 1][j + 1] || !grid[i + 4][j - 4]) {
printf("%d:%d,%d", grid[i][j], i, j);
return 0;
}
}
}
}
}
}
printf("No");
return 0;
}
2. 字符串替换(新)
【问题描述】
编写程序将一个指定文件中某一字符串替换为另一个字符串。要求:(1)被替换字符串若有多个,均要被替换;(2)指定的被替换字符串,大小写无关。
【输入形式】
给定文件名为filein.txt。从控制台输入两行字符串(不含空格,行末尾都有回车换行符),分别表示被替换的字符串和替换字符串。
【输出形式】
将替换后的结果输出到文件fileout.txt中。
【样例输入】
从控制台输入两行字符串:
in
out
文件filein.txt的内容为:
#include <stdio.h>
void main()
{
FILE * IN;
if((IN=fopen(“in.txt”,“r”))==NULL)
{
printf(“Can’t open in.txt!”);
return;
}
fclose(IN);
}
【样例输出】
文件fileout.txt的内容应为:
#outclude <stdio.h>
void maout()
{
FILE * out;
if((out=fopen(“out.txt”,“r”))==NULL)
{
prouttf(“Can’t open out.txt!”);
return;
}
fclose(out);
}
【样例说明】
输入的被替换字符串为in,替换字符串为out,即将文件filein.txt中的所有in字符串(包括iN、In、IN字符串)全部替换为out字符串,并输出保存到文件fileout.txt中。
【评分标准】
该题要求得到替换后的文件内容,共有5个测试点。上传C语言文件名为replace.c。
【参考答案】
从文件中一行一行读入进行输出。可以优化的地方很多,比如KMP等。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int is_matching(char *str, char *sub_str)
{
int len = strlen(sub_str);
for (int i = 0; i < len; i++)
{
if (tolower(*(str + i)) != tolower(*(sub_str + i)))
{
return 0;
}
}
return 1;
}
int main()
{
FILE *in = fopen("filein.txt", "r");
FILE *out = fopen("fileout.txt", "w");
char in_str[100];
char out_str[100];
gets(in_str);
gets(out_str);
char line[200];
while (fgets(line, 200, in) != NULL)
{
int line_len = strlen(line);
for (int i = 0; i < line_len; i++)
{
if (tolower(line[i]) == tolower(in_str[0]) && is_matching(line + i, in_str))
{
fputs(out_str, out);
i += strlen(in_str) - 1;
}
else
{
fputc(line[i], out);
}
}
}
fclose(in);
fclose(out);
return 0;
}
3. 加密文件
【问题描述】有一种加密方法为:其使用一个字母串(可以含重复字母,字母个数不超过50)作为密钥。假定密钥单词串为feather,则先去掉密钥单词中的重复字母得到单词串feathr,然后再将字母表中的其它字母以反序追加到feathr的后面:
f | e | a | t | h | r | z | y | x | w | v | u | s | q | p | o | n | m | l | k | j | i | g | d | c | b |
---|
加密字母的对应关系如下:
a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
f | e | a | t | h | r | z | y | x | w | v | u | s | q | p | o | n | m | l | k | j | i | g | d | c | b |
其中第一行为原始英文字母,第二行为对应加密字母。其它字符不进行加密。编写一个程序,用这种密码加密文件。假定要加密的文件名为encrypt.txt及加密后的文件名为output.txt,并假定输入文件中字母全为小写字母,并且输入密钥也全为小写字母。
【输入形式】从标准输入中输入密钥串,并从文件encrypt.txt中读入要加密的内容。
【输出形式】加密后结果输出到文件output.txt中。
【样例输入】
feather
和文件encrypt.txt中内容,例如被加密的文件encrypt.txt中内容为:
c language is wonderful.
【样例输出】加密后output.txt文件中内容为:
a ufqzjfzh xl gpqthmrju.
【样例说明】首先将给定的密钥单词去除重复字母,然后按照上面的加密对应表对encrypt.txt文件内容进行加密即可得到加密后的文件,其中只对英文字母进行加密对换,并且假设encrypt.txt中的英文字母全是小写字母。
【评分标准】该题要求对文件进行加密,共有5个测试点。提交程序名为encrypt.c
【参考答案】
生成密钥的时候注意换行符。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main()
{
FILE *encrypt = fopen("encrypt.txt", "r");
FILE *output = fopen("output.txt", "w");
char key[55];
fgets(key, 50, stdin);
char corresponds[30];
int cor_p = 0;
int hash_tab[30];
memset(hash_tab, 0, sizeof(int) * 26);
for (int i = 0; key[i] != '\0' && key[i] != '\n'; i++)
{
if (!hash_tab[key[i] - 'a'])
{
corresponds[cor_p++] = key[i];
hash_tab[key[i] - 'a'] = 1;
}
}
for (int i = 25; i >= 0; i--)
{
if (!hash_tab[i])
{
corresponds[cor_p++] = i + 'a';
}
}
char line[100];
while (fgets(line, 100, encrypt) != NULL)
{
for (int i = 0; line[i] != 0; i++)
{
if (isalpha(line[i]))
{
line[i] = corresponds[line[i] - 'a'];
}
}
fputs(line, output);
}
fclose(encrypt);
fclose(output);
return 0;
}
4. 通讯录整理
【问题描述】
读取一组电话号码簿(由姓名和手机号码组成),将重复出现的项删除(姓名和电话号码都相同的项为重复项,只保留第一次出现的项),并对姓名相同手机号码不同的项进行如下整理:首次出现的项不作处理,第一次重复的姓名后面加英文下划线字符_和数字1,第二次重复的姓名后面加英文下划线字符_和数字2,依次类推。号码簿中姓名相同的项数最多不超过10个。最后对整理后的电话号码簿按照姓名进行从小到大排序,并输出排序后的电话号码簿。
【输入形式】
先从标准输入读取电话号码个数,然后分行输入姓名和电话号码,姓名由不超过20个英文小写字母组成,电话号码由11位数字字符组成,姓名和电话号码之间以一个空格分隔,输入的姓名和电话号码项不超过100个。
【输出形式】
按照姓名从小到大的顺序分行输出最终的排序结果,先输出姓名再输出电话号码,以一个空格分隔。
【样例输入】
15
liping 13512345678
zhaohong 13838929457
qiansan 13900223399
zhouhao 18578294857
anhai 13573948758
liping 13512345678
zhaohong 13588339922
liping 13833220099
boliang 15033778877
zhaohong 13838922222
tianyang 18987283746
sunnan 13599882764
zhaohong 13099228475
liushifeng 13874763899
caibiao 13923567890
【样例输出】
anhai 13573948758
boliang 15033778877
caibiao 13923567890
liping 13512345678
liping_1 13833220099
liushifeng 13874763899
qiansan 13900223399
sunnan 13599882764
tianyang 18987283746
zhaohong 13838929457
zhaohong_1 13588339922
zhaohong_2 13838922222
zhaohong_3 13099228475
zhouhao 18578294857
【样例说明】
输入了15个人名和电话号码。其中第一项和第六项完全相同,都是“liping 13512345678”,将第六项删除,第一项保留;
第八项和第一项人名相同,电话不同,则将第八项的人名整理为liping_1;同样,第二项、第七项、第十项、第十三项的人名都相同,将后面三项的人名分别整理为:zhaohong_1、zhaohong_2和zhaohong_3。
最后将整理后的电话簿按照姓名进行从小到大排序,分行输出排序结果。
【评分标准】
该题要求编程实现通讯录的整理与排序,提交程序文件名为sort.c。
【参考答案】
一道比较简单的排序题,注意不需要对电话号码排队,不然就会像我一样看半天不知道问题在哪()。
顺便一提,这个代码是我以前写的,是有很大问题的,但是评测意外地能过,所以测试点真的很弱()。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct people
{
char name[30];
char tel[20];
} tel_dir[100];
int cmp(const void *a, const void *b)
{
struct people *aa = (struct people *)a;
struct people *bb = (struct people *)b;
return strcmp(aa -> name, bb -> name);
}
int main()
{
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%s %s", tel_dir[i].name, tel_dir[i].tel);
}
qsort(tel_dir, n, sizeof(tel_dir[0]), cmp);
int same_name_cnt = 1;
printf("%s %s\n", tel_dir[0].name, tel_dir[0].tel);
for (int i = 1; i < n; i++)
{
if (strcmp(tel_dir[i].name, tel_dir[i - 1].name) == 0)
{
if (strcmp(tel_dir[i].tel, tel_dir[i - 1].tel) == 0)
{
continue;
}
else
{
printf("%s_%d", tel_dir[i].name, same_name_cnt++);
printf(" %s\n", tel_dir[i].tel);
}
}
else
{
printf("%s %s\n", tel_dir[i].name, tel_dir[i].tel);
same_name_cnt = 1;
}
}
return 0;
}
5. 小型图书管理系统
【问题描述】
小明同学特别喜欢买书看书。由于书较多,摆放杂乱,找起来非常麻烦。这学期小明同学上了数据结构与程序设计课后,决定改变这种状况:用C开发一个小型图书管理系统。系统中包含的图书信息有:书名、作者、出版社、出版日期等。首先,图书管理系统对已有的书(原始书库,存放在一个文本文件中)按书名字典序进行(按书名中各字符的ASCII码值由小到大排序)摆放(即将原始无序的图书信息文件生成一个有序的文件,即新书库),以便查找。该管理系统可以对新书库中图书条目进行如下操作:
1.录入。新增书录入到书库中(即从输入中读入一条图书信息插入到已排序好的图按书文件相关位置处)
2.查找。按书名或书名中关键字信息在书库中查找相关图书信息,若有多本书,按字典序输出。
3.删除。输入书名或书名中关键字信息,从书库中查找到相关书并将其删除,并更新书库。
【输入形式】
原始的图书信息(原始书库)保存在当前目录下的books.txt中。
用户操作从控制台读入,首先输入操作功能序号(1代表录入操作,2代表查找操作,3代表删除操作,0代表将已更新的图书信息保存到书库中并退出程序),然后在下一行输入相应的操作信息(录入操作后要输入一条图书信息,查找和删除操作后只要输入书名或书名中部分信息)。程序执行过程中可以进行多次操作,直到退出(输入操作0)程序。
要求:
1、原始文件中的图书信息与录入的图书信息格式相同,每条图书信息都在一行上,包括书名(不超过50个字符)、作者(不超过20个字符)、出版社(不超过30个字符)和出版日期(不超过10个字符),只由英文字母和下划线组成,用一个空格分隔。图书信息总条数不会超过500.
2、下划线字符参加排序。
3、图书不会重名。
【输出形式】
进行录入和删除操作,系统会更新图书信息,但不会在控制台窗口显示任何信息。
进行查找操作后,将在控制台按书名字典序分行输出查找到的图书信息,书名占50个字符宽度,作者占20个字符宽度,出版社占30个字符宽度,出版日期占10个字符宽度,都靠左对齐输出。
最终按字典排序的图书信息保存在当前目录下的ordered.txt中,每条图书信息占一行,格式与查找输出的图书信息相同。
【样例输入】
假设books.txt中保存的原始图书信息为:
The_C_programming_language Kernighan Prentice_Hall 1988
Programming_in_C Yin_Bao_Lin China_Machine_Press 2013
Data_structures_and_Algorithm_Analysis_in_C Mark_Allen_Weiss Addison_Wesley 1997
ANSI_and_ISO_Standard_c Plauger Microsoft_Press 1992
Data_structures_and_program_design_in_C Robert_Kruse Pearson_Education 1997
Computer_network_architectures Anton_Meijer Computer_Science_Press 1983
C_programming_guidelines Thomas_Plum Prentice_Hall 1984
Data_structures_using_C Tenenbaum Prentice_Hall 1990
Operating_system_concepts Peterson Addison_Wesley 1983
Computer_networks_and_internets Douglas_E_Come Electronic_Industry 2017
用户控制台输入信息为:
1
Data_structures_and_C_programs Christopher Addison_Wesley 1988
2
structure
1
The_C_programming_tutor Leon_A_Wortman R_J_Brady 1984
2
rogram
3
rogramming
0
【样例输出】
用户输入“2 structure”后,控制台输出:
Data_structures_and_Algorithm_Analysis_in_C Mark_Allen_Weiss Addison_Wesley 1997
Data_structures_and_C_programs Christopher Addison_Wesley 1988
Data_structures_and_program_design_in_C Robert_Kruse Pearson_Education 1997
Data_structures_using_C Tenenbaum Prentice_Hall 1990
用户输入“2 rogram”后,控制台输出:
C_programming_guidelines Thomas_Plum Prentice_Hall 1984
Data_structures_and_C_programs Christopher Addison_Wesley 1988
Data_structures_and_program_design_in_C Robert_Kruse Pearson_Education 1997
Programming_in_C Yin_Bao_Lin China_Machine_Press 2013
The_C_programming_language Kernighan Prentice_Hall 1988
The_C_programming_tutor Leon_A_Wortman R_J_Brady 1984
ordered.txt文件内容为:
ANSI_and_ISO_Standard_c Plauger Microsoft_Press 1992
Computer_network_architectures Anton_Meijer Computer_Science_Press 1983
Computer_networks_and_internets Douglas_E_Come Electronic_Industry 2017
Data_structures_and_Algorithm_Analysis_in_C Mark_Allen_Weiss Addison_Wesley 1997
Data_structures_and_C_programs Christopher Addison_Wesley 1988
Data_structures_and_program_design_in_C Robert_Kruse Pearson_Education 1997
Data_structures_using_C Tenenbaum Prentice_Hall 1990
Operating_system_concepts Peterson Addison_Wesley 1983
【样例说明】
先读入books.txt中的10条图书信息,按照书名进行字典序排序;用户进行了五次操作,然后退出:第一次操作是插入了一条图书信息,这时有11条图书信息,按书名字典序排序为:
ANSI_and_ISO_Standard_c Plauger Microsoft_Press 1992
C_programming_guidelines Thomas_Plum Prentice_Hall 1984
Computer_network_architectures Anton_Meijer Computer_Science_Press 1983
Computer_networks_and_internets Douglas_E_Come Electronic_Industry 2017
Data_structures_and_Algorithm_Analysis_in_C Mark_Allen_Weiss Addison_Wesley 1997
Data_structures_and_C_programs Christopher Addison_Wesley 1988
Data_structures_and_program_design_in_C Robert_Kruse Pearson_Education 1997
Data_structures_using_C Tenenbaum Prentice_Hall 1990
Operating_system_concepts Peterson Addison_Wesley 1983
Programming_in_C Yin_Bao_Lin China_Machine_Press 2013
The_C_programming_language Kernighan Prentice_Hall 1988
第二次操作是查找书名包含structure的图书,有4本图书信息按照格式要求输出到屏幕;第三次操作又插入了一条图书信息,这时有12条图书信息;第四次操作查找书名包含rogram的图书,有6本图书信息按照格式要求输出到屏幕;第五次操作是删除书名包含rogramming的图书信息,有四条图书信息要删除,剩下八条图书信息;最后退出程序前将剩余的八条图书信息按照格式要求存储在ordered.txt文件中。
【评分标准】
该程序要求编写图书管理系统。提交程序文件名为books.c。
【参考答案】
按要求写就行,我这边删除操作的做法是把书名用最大字典序覆盖掉,然后再排序的方式。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define LOGI 1
#define SEAR 2
#define DELE 3
#define EXIT 0
struct book
{
char name[50];
char author[20];
char publisher[30];
char publish_data[10];
} lib[500];
int cmp(const void *a, const void *b)
{
return strcmp(((struct book *)a)->name, ((struct book *)b)->name);
}
int main()
{
FILE *books = fopen("books.txt", "r");
FILE *ordered = fopen("ordered.txt", "w");
int n = 0;
while (~fscanf(books, "%s %s %s %s", lib[n].name, lib[n].author, lib[n].publisher, lib[n].publish_data))
{
n++;
}
qsort(lib, n, sizeof(lib[0]), cmp);
int order;
scanf("%d", &order);
while (order != EXIT)
{
switch (order)
{
case LOGI:
scanf("%s %s %s %s", lib[n].name, lib[n].author, lib[n].publisher, lib[n].publish_data);
qsort(lib, ++n, sizeof(lib[0]), cmp);
break;
case SEAR:;
char sea_target[50];
scanf("%s", sea_target);
for (int i = 0; i < n; i++)
{
if (strstr(lib[i].name, sea_target) != NULL)
{
printf("%-50s%-20s%-30s%-10s\n", lib[i].name, lib[i].author, lib[i].publisher, lib[i].publish_data);
}
}
break;
case DELE:;
char del_target[50];
int del_cnt = 0;
scanf("%s", del_target);
for (int i = 0; i < n; i++)
{
if (strstr(lib[i].name, del_target) != NULL)
{
memset(lib[i].name, 126, sizeof(lib[i].name));
del_cnt++;
}
}
qsort(lib, n, sizeof(lib[0]), cmp);
n -= del_cnt;
break;
default:
break;
}
scanf("%d", &order);
}
for (int i = 0; i < n; i++)
{
fprintf(ordered, "%-50s%-20s%-30s%-10s\n", lib[i].name, lib[i].author, lib[i].publisher, lib[i].publish_data);
}
fclose(books);
fclose(ordered);
return 0;
}