# 东华oj-进阶题第84题-摩托车

84 摩托车

					摩托车的型号，摩托车的颜色和摩托车马达的类型。


a1

a2


a1                   yellow              r1

a3                     red                 r3

a4                    blue                 r4


3 5
a1
a2
a3
b1 blue r1
c1 red r2
d1 blue r3
a1 green r2
a2 yellow r1
1 1
a1
b1 blue r1


a1 green r2
a2 yellow r1


## 代码：

/*
T84 摩托车
*/

#include<stdio.h>
#include<string.h>
#define MAX_SIZE 105

typedef struct Motorbike {
char motorbikeType[3];// 摩托车型号
char color[15];// 颜色
char motorType[3];// 马达型号
} Motorbike;

void sortByType(Motorbike bikes[], int n);

int main() {
//printf("%d\n", strcmp("a1", "a2"));
int flag = 0;
int i = 0, j = 0;
int n = 0, m = 0;
Motorbike req[MAX_SIZE];// 客户需要的摩托车
Motorbike own[MAX_SIZE];// 明明工厂拥有的摩托车

while (scanf("%d%d", &n, &m) != EOF) {
for (i = 0; i < n; i++)
scanf("%s", req[i].motorbikeType);

for (i = 0; i < m; i++)
scanf("%s%s%s", own[i].motorbikeType, own[i].color, own[i].motorType);

sortByType(req, n);
flag = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (strcmp(req[i].motorbikeType, own[j].motorbikeType) == 0) {
flag = 1;
printf("%s %s %s\n", own[j].motorbikeType,
own[j].color, own[j].motorType);
}
}
}
if (!flag) {
}
}

return 0;
}

// 按照摩托车型号排序
void sortByType(Motorbike bikes[], int n) {
int i = 0, j = 0;
Motorbike temp;

for (i = n - 1; i > 0; i--) {
for (j = 0; j < i; j++) {
if (strcmp(bikes[j].motorbikeType, bikes[j + 1].motorbikeType) == 1) {
temp = bikes[j];
bikes[j] = bikes[j + 1];
bikes[j + 1] = temp;
}
}
}
}


©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客