用c语言编写统计分析 1. 可统计当前排队人数最多的窗口业务类型 2.可按评分高低顺序展示所有窗口 3.可按服务的顾客总数顺序展示所有窗口
时间: 2024-02-26 15:56:25 浏览: 26
好的,以下是用 C 语言实现统计分析的代码:
1. 统计当前排队人数最多的窗口业务类型
```
#include <stdio.h>
int main()
{
// 定义窗口业务类型和排队人数
int queueCount[3] = {10, 20, 30};
char *businessType[3] = {"A", "B", "C"};
int i, maxQueueCount = queueCount[0], maxIndex = 0;
// 遍历数组找到排队人数最多的窗口业务类型
for (i = 1; i < 3; i++) {
if (queueCount[i] > maxQueueCount) {
maxQueueCount = queueCount[i];
maxIndex = i;
}
}
printf("当前排队人数最多的窗口业务类型是:%s,排队人数为:%d\n", businessType[maxIndex], maxQueueCount);
return 0;
}
```
2. 按评分高低顺序展示所有窗口
```
#include <stdio.h>
#include <stdlib.h>
typedef struct {
char *name;
int score;
} Window;
int compare(const void *a, const void *b)
{
Window *windowA = (Window *)a;
Window *windowB = (Window *)b;
return windowB->score - windowA->score;
}
int main()
{
// 定义窗口的评分和名称
Window windows[3] = {{"A", 90}, {"B", 80}, {"C", 95}};
int i;
// 按照评分高低排序
qsort(windows, 3, sizeof(Window), compare);
// 展示所有窗口的评分
printf("所有窗口的评分如下:\n");
for (i = 0; i < 3; i++) {
printf("%s:%d分\n", windows[i].name, windows[i].score);
}
return 0;
}
```
3. 按服务的顾客总数顺序展示所有窗口
```
#include <stdio.h>
#include <stdlib.h>
typedef struct {
char *name;
int customerCount;
} Window;
int compare(const void *a, const void *b)
{
Window *windowA = (Window *)a;
Window *windowB = (Window *)b;
return windowB->customerCount - windowA->customerCount;
}
int main()
{
// 定义窗口的服务顾客总数和名称
Window windows[3] = {{"A", 100}, {"B", 80}, {"C", 120}};
int i;
// 按照服务的顾客总数排序
qsort(windows, 3, sizeof(Window), compare);
// 展示所有窗口的服务顾客总数
printf("所有窗口的服务顾客总数如下:\n");
for (i = 0; i < 3; i++) {
printf("%s:%d人\n", windows[i].name, windows[i].customerCount);
}
return 0;
}
```
以上是用 C 语言实现统计分析的代码,希望能够帮到你。