选择+填空
选择题
- 【单选题】
设某一非空的单循环链表的头指针(指向第一个结点的指针)为Head,尾指针(指向最后一个结点的指针)为Rear,则下列条件判断结果一定为真的是a 。
A. Head== Rear->link B. Head== Rear->link->link
C. Rear== Head->link D. Rear== Head->link->link - 若线性表最常用的运算是存取第i个元素及其前驱的值,则采用c 存储方式节省时间。
A.单链表 B.双链表 C.顺序表 D.循环单链表 - 【单选题】
下列语句中,能正确进行字符串赋值的是c 。
A. char s[10]; s=“BUAA”; B. char* sp; *sp=“BUAA” ;
C. char *sp=“BUAA”; D. char s[10]; *s=“BUAA”; - 若有以下说明和语句:
struct student
{
int age;
int num;
}std, *p;
p = &std;
则以下对结构变量 std 中成员 age 的引用方式不正确的是d
A. std.age
B. p->age
C. (*p).age
D. *p.age - 设p指针指向单链表(单链表长度为n)中的某个结点(p≠NULL),若只知道指向该单链表第一个结点的指针和p指针,则在p指针所指结点之前和p指针所指结点之后插入一个结点的时间复杂度分别是d 。
A. O(1)和O(n) B. O(1)和O(1) C. O(n)和O(n) D. O(n)和O(1) - 若有语句 int *point,a=4; 和 point=&a; 下面均代表地址的一组选项是d
A. a , point , *&a ;
B. &(*a) , &a , *point ;
C. *(&point) , *point , &a ;
D. &a , &(*point) , point ; - 若要删除非空线性链表中由p所指的链结点的直接后继链结点(由p->link指向),则需依次执行b 。
A.r=p->link; p->link=r; free®;
B.r=p->link; p->link=r->link; free®;
C.r=p->link; p->link=r->link; free§;
D.p->link=p->link->link; free§;
填空题
-
有如下定义:
struct point{
float x,y;
};
struct triangle{
struct point a,b,c;
}tr;
若要将三角形tr的顶点b的x坐标设置为1.5,请将该赋值语句补充完整:
tr.b.x=1.5; -
若有如下定义:
char pls[1000],buf[512];
int i=0;
下面的语句是按行从标准输入读入一篇文章(每行字符数少于511,行数少于1000)
保存到pls中,并且要求尽可能节省空间,请将语句补充完整:
while(fgets(buf,512,stdin)!=NULL){
pls[i]=(char)malloc(strlen(buf)+1);
strcpy(pls[i],buf);
i++;
} -
若有函数定义为:
int func(int n)
{
if(n<=1)
return 1;
else
return (2+n*func(n-1));
}
假设m为int类型,则执行语句:m=func(5);后,m的值为:292
大题
1. 密 码 对 应 表
问题描述
有一种加密方法为:其使用一个字符串(可以含重复字母,字符个数不超过50)作为密钥。例如:若密钥字符串为Fea25Ther,则需 要先将大写字母转换成小写字母,并去掉密钥单词中的非字母及重复字母得到单词串feathr,然后将其反序,最后将字母表中的其它字母以反序追加到后面:
r | h | t | a | e | f | 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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
r | h | t | a | e | f | z | y | x | w | v | u | s | q | p | o | n | m | l | k | j | i | g | d | c | b |
编写程序根据输入的密钥,生成相应的密码对应表串。
输入形式
从标准输入读入密钥字符串(字符个数不超过50,其中可包含空白符或其它非字母字符),末尾有换行符(不属于密钥字符串)。
输出形式
先向控制台输出原字母表,然后在下一行输出生成的对应密码表。
样例输入
Fea25Ther
样例输出
a r
b h
c t
d a
e e
f f
g z
h y
i x
j w
k v
l u
m s
n q
o p
p o
q n
r m
s l
t k
u j
v i
w g
x d
y c
z b
样例说明
输入的密钥字符串为Fea25Ther,先将大写字母转换成小写字母,并去掉密钥单词中的非字母及重复字母得到单词串feathr,然后将其反序,最后将字母表中的其它字母以反序追加到后面,便得到密码表。
评分标准
该题要求生成密码对应表,提交程序名为:key.c。
笔者的AC代码
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
typedef long long ll;
char read[10000];//存处理后的密钥字符串
int read_i = 0;
char key[10000];//存逆序的密码对应表(即输出时逆序输出)
int key_i = 0;
int visit[10000];//记录被使用过的字母
int main()
{
char x, store;
while (1)
{
x = getchar();
int flag_alpha = 0;
if (x == '\n' || x == '\r')
break;
if (x >= 'A' && x <= 'Z')
{
store = x - 'A' + 'a';
flag_alpha = 1;
}
else if (x >= 'a' && x <= 'z')
{
store = x;
flag_alpha = 1;
}
if (flag_alpha)
{
int flag = 0;
for (int i = 0; i < read_i; i++)
{
if (store == read[i])
flag = 1;
}
if (!flag)
{
read[read_i++] = store;
visit[store - 'a'] = 1;
}
}
}
for (int i = 0; i < 26; i++)
{
if (!visit[i])
key[key_i++] = i + 'a';
}
strcat(key, read);
for (int i = 25; i >= 0; i--)
{
printf("%c %c\n", 25 - i + 'a', key[i]);
}
return 0;
}
2. 基 于 前 移 法 的 链 表 查 找
见文档
链接:https://pan.baidu.com/s/1kRHLut0xF3VcCKXIwghSTg?pwd=w05t
提取码:w05t
笔者的AC代码
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
typedef long long ll;
typedef struct Node
{
int num;
int times;
struct Node *next;
} Node, *Nodeptr;
Nodeptr List_init();
void List_create(Nodeptr node, int data);
Nodeptr List_destroy(Nodeptr HeadNode);
int list_i = 0;
int main()
{
Nodeptr head = List_init();
Nodeptr node = head;
int count, a;
int ans = 0;
scanf("%d", &count);
for (int i = 0; i < count; i++)
{
scanf("%d", &a);
if (list_i == 0)
{
List_create(node, a);
list_i++;
}
else
{
Nodeptr node_pre = head;
node = head->next;
int flag = 0;
for (int i = 0; i < list_i; i++)
{
ans++;
if (node->num == a)
{
flag = 1;
node_pre->next = node->next;
node->next = head->next;
head->next = node;
node->times++;
break;
}
if (node->next == NULL)
break;
node_pre = node;
node = node->next;
}
if (flag == 0)
{
List_create(node, a);
list_i++;
}
}
}
node = head->next;
for (int i = 0; i < 5; i++)
{
printf("%d %d\n", node->num, node->times);
if (node->next == NULL)
break;
node = node->next;
}
printf("%d", ans);
List_destroy(head);
return 0;
}
Nodeptr List_init()
{
Nodeptr HeadNode = (Nodeptr)malloc(sizeof(Node));
if (HeadNode == NULL)
{
printf("Insufficient space cache\n");
return HeadNode;
}
HeadNode->num = 0; // 改这个
HeadNode->times = 0;
HeadNode->next = NULL;
return HeadNode;
}
void List_create(Nodeptr node, int data) // 在node后面插入一个结点,不改变node的位置
{
Nodeptr new;
new = (Nodeptr)malloc(sizeof(Node));
if (new == NULL)
printf("Insufficient space cache\n");
new->num = data;
new->times = 1;
new->next = node->next;
node->next = new;
}
Nodeptr List_destroy(Nodeptr HeadNode) // HeadNode为头结点,返回HeadNode
{
Nodeptr now = HeadNode->next;
while (now != NULL)
{
Nodeptr nextnode = now->next;
free(now);
now = nextnode;
}
HeadNode->next = NULL;
return HeadNode;
}
附:2022级猪脚说
链接:https://pan.baidu.com/s/1gvR3SteRwwYSbGD4PtsH7A?pwd=sqxa
提取码:sqxa