mirror of
https://github.com/renbaoshuo/202401-programming-assignments.git
synced 2024-12-16 15:44:39 +00:00
33 lines
516 B
C
33 lines
516 B
C
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#define MAXS 80
|
|
|
|
int getindex(char *s);
|
|
|
|
int main() {
|
|
int n;
|
|
char s[MAXS];
|
|
|
|
scanf("%s", s);
|
|
n = getindex(s);
|
|
if (n == -1) printf("Not Found\n");
|
|
else printf("%d\n", n);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/* 你的代码将被嵌在这里 */
|
|
|
|
const char DATA[][10] = {"", "red", "blue", "yellow", "green", "black"};
|
|
|
|
int getindex(char *s) {
|
|
for (int i = 0; i < 7; i++) {
|
|
if (strcmp(s, DATA[i]) == 0) {
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
}
|