# 12544 - Simple Web Crawer ## 題解: 使用fgets和strtok讀取和分解字串 title後的字串就要輸出, 遇到/a就把答案加一 ## Code: ```cpp #include <stdio.h> #include <string.h> #include <stdlib.h> int num, flag; char s[1005], del[] = {'<', '>', '\0'}; void check(char* str){ char t[] = "title", a[] = "/a"; if(flag){ printf("%s\n", str); flag = 0; return; } if(strcmp(str, t) == 0) flag = 1; if(strcmp(str, a) == 0) num++; } int main(){ while(fgets(s, 1005, stdin)){ char *token = strtok(s, del); while(token != NULL){ check(token); token = strtok(NULL, del); } } printf("%d\n", num); return 0; } ``` ###### tags: `NTHUOJ`