50208. Cyclomatic Complexity

難度:3/5

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int is_keyword(char* s){
return (strcmp(s, "if") == 0) || (strcmp(s, "case") == 0) ||
(strcmp(s, "for") == 0) || (strcmp(s, "while") == 0);
}
int have_qm(char* s){
while(*s != '\0'){
if(*s == '?') return 1;
s++;
}
return 0;
}

int main(){
int cnt = 0;
char s[2048], sep[24] = "\t\n ()[]{};";
while(fgets(s, 2048, stdin) != NULL){
char* token = strtok(s, sep);
while(token != NULL){
if(is_keyword(token)) cnt++;
if(have_qm(token)) cnt++;
token = strtok(NULL, sep);
}
}
printf("%d\n", cnt);
}

50208. Cyclomatic Complexity
https://aaronlin1229.github.io/judgegirl_50208/
Author
Akizumi
Posted on
July 17, 2023
Licensed under