题解 | #IP地址#

IP地址

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

#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    while(cin>>s){
        int dotCount = 0;
        for(int i =0;i<s.length();i++)
            if(s[i]=='.')dotCount++;
        if(dotCount!=3)cout<<"No!";
        else{
            vector<int>v;
            while(s.length()!=0){
                if(s.find('.')!=-1)
                    v.push_back(stoi(s.substr(0,s.find('.'))));
                else{
                    v.push_back(stoi(s));
                    break;
                }
                s = s.substr(s.find('.')+1,s.length());
            }
            bool isRight = true;
            for(auto a:v)
                if(a>255 || a<0)isRight=false;
            cout<<(isRight?"Yes!":"No!")<<endl;
        }
    }
}
// 64 位输出请用 printf("%lld")

qd

全部评论

相关推荐

07-09 20:50
门头沟学院 Java
码农索隆:1.教育背景和荣誉证书合二为一。 2.获奖项目理一遍,你做了什么,对你求职的岗位有什么帮助,没有就删掉。 3.技能特长和教育背景交换位置。 4.技能特长写的太差,上网上找简历参考。都不用问你别的,一个redis就能把你问住,写写你具体会redis哪些方面的知识。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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