题解 | IP地址

IP地址

https://www.nowcoder.com/practice/2359e23180194f99828f5cd9c764236a

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

bool func(string str) {
    bool flag = true;
    for (int i = 0; i < str.size(); i++) {
        int res = 0, j;
        for (j = i; isdigit(str[j]); j++) {
            res += str[j] - '0';
            res *= 10;
        }
        res /= 10;
        if (res < 0 || res > 255) {
            flag = false;
            break;
        }
        i = j;
    }
    return flag;
}

int main() {
    string str;
    while (cin >> str) {
        if (func(str)) {
            cout << "Yes!" << endl;
        } else {
            cout << "No!" << endl;
        }
    }
    return 0;
}

全部评论

相关推荐

点赞 评论 收藏
分享
点赞 评论 收藏
分享
06-26 22:20
门头沟学院 Java
码农索隆:让你把简历发给她,她说一些套话,然后让你加一个人,说这个人给你改简历,然后开始卖课
我的求职精神状态
点赞 评论 收藏
分享
昨天 13:42
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务