-
2021-07-28 15:44:59
本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义如下:
struct ListNode { char code[8]; struct ListNode *next; };
这里学生的学号共7位数字,其中第2、3位是专业编号。计算机专业的编号为02。
函数接口定义:
int countcs( struct ListNode *head );
其中
head
是用户传入的学生学号链表的头指针;函数countcs
统计并返回head
链表中专业为计算机的学生人数。裁判测试程序样例:
#include <stdio.h> #include <stdlib.h> #include <string.h> struct ListNode { char code[8]; struct ListNode *next; }; struct ListNode *createlist(); /*裁判实现,细节不表*/ int countcs( struct ListNode *head ); int main() { struct ListNode *head; head = createlist(); printf("%d\n", countcs(head)); return 0; } /* 你的代码将被嵌在这里 */
输入样例:
1021202 2022310 8102134 1030912 3110203 4021205 #
输出样例:
3
代码如下:
int countcs( struct ListNode *head ) { int a=0; struct ListNode *p; p=head; while(p) { if((p->code[1]=='0')&&(p->code[2]=='2')) a++; p=p->next; } return a; }
更多相关内容 -
[PTA]实验11-2-7 统计专业人数
2021-05-30 22:54:07本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义如下: struct ListNode { char code[8]; struct ListNode *next; }; 这里学生的学号共7位数字,其中第2、3位是专业编号。计算机...本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义如下:
struct ListNode { char code[8]; struct ListNode *next; };
这里学生的学号共7位数字,其中第2、3位是专业编号。计算机专业的编号为02。
函数接口定义:
int countcs( struct ListNode *head );
其中head是用户传入的学生学号链表的头指针;函数countcs统计并返回head链表中专业为计算机的学生人数。
裁判测试程序样例:
#include <stdio.h> #include <stdlib.h> #include <string.h> struct ListNode { char code[8]; struct ListNode *next; }; struct ListNode *createlist(); /*裁判实现,细节不表*/ int countcs( struct ListNode *head ); int main() { struct ListNode *head; head = createlist(); printf("%d\n", countcs(head)); return 0; } /* 你的代码将被嵌在这里 */
输入样例:
1021202 2022310 8102134 1030912 3110203 4021205 #
输出样例:
3
- 提交结果:
- 源码:
#include <stdio.h> #include <stdlib.h> #include <string.h> struct ListNode { char code[8]; struct ListNode* next; }; struct ListNode* createlist(); /*裁判实现,细节不表*/ int countcs(struct ListNode* head); int main() { struct ListNode* head; head = createlist(); printf("%d\n", countcs(head)); return 0; } /* 你的代码将被嵌在这里 */ struct ListNode* createlist() { struct ListNode* head, * tail, * temp; // 头节点、尾节点、临时节点 head = tail = temp = NULL; char code[8]; scanf("%s", &code); // 输入以'#'结束 while (strcmp(code,"#")!=0) { // 为临时节点分配内存 temp = (struct ListNode*)malloc(sizeof(struct ListNode)); // 临时节点指向空 temp->next = NULL; // 存入数据 strcpy(temp->code, code); // 将第一个数据存入头结点 if (head == NULL) { head = temp; } else { // 将临时节点连接到链表尾 tail->next = temp; } // 更新尾节点 tail = temp; scanf("%s", &code); } return head; } int countcs(struct ListNode* head) { int count = 0; // 链表为空,返回0 if (head == NULL) { return count; } while (head) { char code[8]; // 将链表中的数据存入临时字符数组 strcpy(code, head->code); // 符合计算机专业代码"02" if (code[1] == '0' && code[2] == '2') { count++; } head = head->next; } return count; }
-
6-5 统计专业人数 (15分)
2021-01-05 20:38:18本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义如下: struct ListNode { char code[8]; struct ListNode *next; }; 这里学生的学号共7位数字,其中第2、3位是专业编号。计算机...本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义如下:
struct ListNode { char code[8]; struct ListNode *next; };
这里学生的学号共7位数字,其中第2、3位是专业编号。计算机专业的编号为02。
函数接口定义:
int countcs( struct ListNode *head );
其中head是用户传入的学生学号链表的头指针;函数countcs统计并返回head链表中专业为计算机的学生人数。
裁判测试程序样例:
#include <stdio.h> #include <stdlib.h> #include <string.h> struct ListNode { char code[8]; struct ListNode *next; }; struct ListNode *createlist(); /*裁判实现,细节不表*/ int countcs( struct ListNode *head ); int main() { struct ListNode *head; head = createlist(); printf("%d\n", countcs(head)); return 0; } /* 你的代码将被嵌在这里 */
输入样例:
1021202 2022310 8102134 1030912 3110203 4021205 #
输出样例:
3
/* 你的代码将被嵌在这里 */
int countcs( struct ListNode *head ) { struct ListNode *p; p=head; int a=0; if(head!=NULL) { do { if(p->code[1]=='0'&&p->code[2]=='2') a++; p=p->next; }while(p!=NULL); } return a; }
-
PTA6-10 统计专业人数 (15分)
2020-04-18 16:59:27本人菜鸟,还请诸位大佬多多指点!!! #include <stdio.h> #include <stdlib.h> #include <string.h> struct ListNode { char code[8]; struct ListNode *next; }; struct ListNode *...int...本人菜鸟,还请诸位大佬多多指点!!!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>struct ListNode {
char code[8];
struct ListNode *next;
};struct ListNode *createlist(); /裁判实现,细节不表/
int countcs( struct ListNode *head );int main()
{
struct ListNode *head;head = createlist(); printf("%d\n", countcs(head)); return 0;
}
/* 你的代码将被嵌在这里 */
struct ListNode *createlist() //输入函数,本题不需要;
{
struct ListNode *head,q,p;
head=(struct ListNode)malloc(sizeof(struct ListNode)); //定义一个有头结点的链表;
head->next=NULL;
q=head;
char input[8];
while(1)
{
scanf("%s",input);
if(!strcmp(input,"#")) //字符串比较函数确定有没有符合条件的字符串;
break;
p=(struct ListNode)malloc(sizeof(struct ListNode));
strcpy(p->code,input);
q->next=p;
q=p;
}
q->next=NULL;
return head->next; //返回头结点的下一个结点,即有字符串的第一个结点;
}int countcs( struct ListNode *head )
{
struct ListNode *q;
q=head; //此时链表无头结点;
int num=0;
while(q!=NULL)
{
if(q->code[1]‘0’&&q->code[2]‘2’)
{
num++;
}
q=q->next;
}
return num;
} -
统计专业人数
2017-09-06 17:36:36本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义如下: struct ListNode { char code[8]; struct ListNode *next; }; 这里学生的学号共7位数字,其中第2、3位是专业编号。... -
6-3 统计专业人数
2019-10-14 18:50:196-3 统计专业人数 (20 分)本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义如下: struct ListNode { char code[8]; struct ListNode *next; }; 这里学生的学号共7位数字,其中... -
8-6-3 统计专业人数 (15 分)
2021-05-03 23:44:218-6-3 统计专业人数 (15 分) 本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义如下: struct ListNode { char code[8]; struct ListNode *next; }; 这里学生的学号共7位数字,... -
6-26 统计专业人数 (15分)
2020-04-20 00:53:09本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义如下: struct ListNode { char code[8]; struct ListNode *next; }; 这里学生的学号共7位数字,其中第2、3位是专业编号。... -
PTA: 统计专业人数 (15分)(C语言)
2020-04-15 08:47:20本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义如下: struct ListNode { char code[8]; struct ListNode *next; }; 这里学生的学号共7位数字,其中第2、3位是专业编号。计算机专业... -
6-2 统计专业人数 (8 分)本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义...
2022-03-28 11:40:306-2 统计专业人数 (8 分) 本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义如下: struct ListNode { char code[8]; struct ListNode *next; }; 这里学生的学号共7位数字,其中第2... -
6-2 统计专业人数 (10分)
2020-04-29 08:44:37本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义如下: struct ListNode { char code[8]; struct ListNode *next; }; 这里学生的学号共7位数字,其中第2、3位是专业编号。计算机... -
6-3 统计专业人数 (15 分)
2019-08-19 10:50:21本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义如下: struct ListNode { char code[8]; struct ListNode *next; }; 这里学生的学号共7位数字,其中第2、3位是专业编号。... -
实验11-2-7 统计专业人数 (15 分)
2019-03-08 23:11:36实验11-2-7 统计专业人数 (15 分) 本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义如下: struct ListNode { char code[8]; struct ListNode *next; }; 这里学生的学号共7位数字,... -
统计专业人数 (10 分)
2018-11-30 19:11:026-7 统计专业人数 (10 分) 本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义如下: struct ListNode { char code[8]; struct ListNode *next; }; 这里学生的学号共7位... -
6-3 统计专业人数 (15 分)
2019-10-04 20:58:19本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义如下: struct ListNode { char code[8]; struct ListNode *next; }; 这里学生的学号共7位数字,其中第2、3位是... -
统计专业人数。本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。
2020-05-23 22:49:35统计专业人数 本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义如下: struct ListNode { char code[8]; struct ListNode *next; }; 这里学生的学号共7位数字,其中第2、3位是专业... -
leetcode580. 统计各专业学生人数(SQL)
2020-12-15 00:57:21写一个查询语句,查询 department 表中每个专业的学生人数 (即使没有学生的专业也需列出)。 将你的查询结果按照学生人数降序排列。 如果有两个或两个以上专业有相同的学生数目,将这些部门按照部门名字的字典序... -
实验11-2-7 统计专业人数 (15 分)
2021-02-09 14:19:23本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义如下: struct ListNode { char code[8]; struct ListNode *next; }; 这里学生的学号共7位数字,其中第2、3位是专业编号。计算机... -
统计各专业学生人数
2020-05-18 19:21:02专业表 SELECT dept_name, ifnull(z_studen.cou, 0) AS '人数' FROM ( SELECT dept_id, COUNT(*) AS cou FROM z_studen GROUP BY dept_id ) z_studen RIGHT JOIN z_department ON z_... -
实验11-2-7 统计专业人数 (15分)
2020-03-22 12:51:09本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。 这里学生的学号共7位数字,其中第2、3位是专业编号。计算机专业的编号为02。 函数接口定义: int countcs( struct ListNode *head ); 其中head... -
580. 统计各专业学生人数 难度:中等
2019-07-17 21:55:061# student表,按dept_id分组,统计数量 2# 以department,联查,记得处理空值ifnull(cou,0) as student_number 3、提交记录 select dept_name,ifnull(cou,0) as student_number from( select dept_id,count... -
基于MATLAB的数字图像人数统计.pdf
2021-07-10 13:30:37基于MATLAB的数字图像人数统计.pdf -
mysql实现每个专业分数段统计人数
2021-02-01 19:13:12我的表结构student_info| id |name |profession|score||--|--|--|--||id|姓名|分数|专业|按分数段统计400到500人数,300到400人数selectcount(case when score between 400 and 500 then 1 end) as 400到500,count... -
mysql实现每个专业分数段统计人数 | 秒速技术
2021-02-07 13:14:50我的表构造student_info | id |name |profession|score| |--|--|--|--| |id|姓名|分数|专业|以上就是mysql实现每个专业分数段统计人数的具体内容400到500人数,300到400人数select count(case when score between ... -
每日sql-统计各个专业人数(包括专业人数为0的)
2022-01-27 11:17:45每日sql-统计各个专业人数(包括专业人数为0的) DDL CREATE TABLE IF NOT EXISTS student (student_id INT,student_name VARCHAR(45), gender VARCHAR(6), dept_id INT);CREATE TABLE IF NOT EXISTS department ...