所以作业说我应该写一个程序来打印总数超过18的数字,不包括16,或者其中一个单词: ABSINTH,BEER,BRANDY, CHAMPAGNE,GIN,RUM,SAKE,TEQUILA,VODKA,WHISKEY,WINE 。
例如:输入:
7 //specify the number of inputs
18
Vodka
16
Coke
19
17
Gin
输出:3
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
char *p (char str[]){
int i=0;
while (str[i]){
str[i]=tolower(str[i]);
i++;
}
return str;
}
bool check(char a[]){
int i=0;
while (a[i]){
if (!isdigit(a[i]))
return false;
i++;
}
return true;
}
int main (){
int n,t;
int s=0;
char a[20];
#ifndef ONLINE_JUDGE
freopen ("input.txt","r",stdin);
#endif
scanf ("%d\n",&n);
for (int i=0;i<n;i++){
t=0;
gets (a);
if (check(a)){
t = atoi (a);
if (t<18&&t!=16)
s++;
}
else if (!strcmp(p(a),"absinth")||!strcmp(p(a),"beer")||!strcmp(p(a),"brandy")||!strcmp(p(a),"champagne")||!strcmp(p(a),"gin")||!strcmp(p(a),"rum")||!strcmp(p(a),"sake")||!strcmp(p(a),"tequila")||!strcmp(p(a),"vodka")||!strcmp(p(a),"whiskey")||!strcmp(p(a),"wine"))
s++;
}
printf ("%d",s);
return 0;
}
输出正如作业所要求的那样,但不知何故,在线评委不断告诉我代码是不正确的。有人可以告诉我我可能在哪里错了吗?