题目比较简单容易理解,这里我们直接模拟即可。也欢迎大家一起讨论交流呀!
#include <stdio.h> #include <string.h> int main() { char s[1000005]; while (gets(s) != NULL) { int i = 0, n = strlen(s); int flag = 1; while (i < n) { int num = 0; while (i < n && s[i] != '.') { num *= 10; num += s[i] - '0'; i ++; } if (!(num >= 0 && num <= 255)) { flag = 0; break; } i++; } if (flag) printf("Yes!\n"); else printf("No!\n"); } return 0; }