班主任朱老师喜欢在微信群中发布通知,让家长们接龙。某天朱老师发布了一则通知,“清明节放假三天,收到请回复”,于是家长们开始接龙: 1.png 但某个家长接龙时突然手滑了一下,回复成:“收到,猪老师”,于是后面的家长进行复制粘贴,也回复了“收到,猪老师",接龙变成了这样: 2.png 突然某个家长发现接错了,于是重新进行了接龙(当然,已经接错的是无法删除的),接龙终于又正常了: 3.png 结果很明显,当朱老师统计接龙信息时,他很生气! 输入格式: 第一行给出家长人数N(N<=100000)于是给家长编号为1~N,接下来若干行给出家长的接龙信息,每行表示一条接龙信息,格式为:收到,朱老师 家长编号,家长编号前有一个空格,接龙的最后一行为#,表示接龙结束,题目假设第一条接龙信息总是正确的。 输出格式: 在第一行中输出首个接错龙的家长编号;第二行按升序输出接错龙的家长编号,编号间用一个空格分隔,最后一个编号后面无空格,注意改正错误的家长不能被统计在里面;第三行按升序输出未接龙家长的编号,编号间用一个空格分隔,最后一个编号后面无空格。若没有家长接龙,输出"no one!";若没有家长接错龙,第二行输出"all right!",若所有家长都参与了接龙,第三行输出"everyone is here!" 用c语言完成
时间: 2024-03-11 07:44:15 浏览: 26
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Node {
char name[10];
int id;
struct Node* next;
};
struct Node* createNode(char name[], int id) {
struct Node* node = (struct Node*)malloc(sizeof(struct Node));
strcpy(node->name, name);
node->id = id;
node->next = NULL;
return node;
}
struct Node* insertNode(struct Node* head, char name[], int id) {
struct Node* node = createNode(name, id);
if (head == NULL) {
return node;
}
struct Node* p = head;
while (p->next != NULL) {
p = p->next;
}
p->next = node;
return head;
}
int main() {
int n;
scanf("%d", &n);
struct Node* head = NULL;
for (int i = 1; i <= n; i++) {
char name[10];
int id;
scanf("%s %*c%d", name, &id);
head = insertNode(head, name, id);
}
char line[20];
fgets(line, 20, stdin); // 读取接龙信息中的空行
int wrongId = 0;
struct Node* wrongHead = NULL;
struct Node* notJoinHead = NULL;
int joinCount = 0;
int* joinList = (int*)malloc(n * sizeof(int));
for (int i = 1; ; i++) {
fgets(line, 20, stdin);
if (line[0] == '#') {
break;
}
char name[10];
int id;
sscanf(line, "%*s %s %d", name, &id);
if (id != i + 1) {
if (wrongId == 0) {
wrongId = id;
}
wrongHead = insertNode(wrongHead, name, id);
}
joinList[joinCount++] = id;
}
if (wrongId == 0) {
printf("all right!\n");
} else {
printf("%d\n", wrongId);
struct Node* p = wrongHead;
while (p != NULL) {
printf("%d%c", p->id, (p->next == NULL ? '\n' : ' '));
p = p->next;
}
}
if (joinCount == n) {
printf("everyone is here!\n");
} else {
for (int i = 1; i <= n; i++) {
int found = 0;
for (int j = 0; j < joinCount; j++) {
if (joinList[j] == i) {
found = 1;
break;
}
}
if (!found) {
notJoinHead = insertNode(notJoinHead, "", i);
}
}
if (notJoinHead == NULL) {
printf("no one!\n");
} else {
struct Node* p = notJoinHead;
while (p != NULL) {
printf("%d%c", p->id, (p->next == NULL ? '\n' : ' '));
p = p->next;
}
}
}
return 0;
}
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)