题解 | #IP地址#

IP地址

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

#include <iostream>
using namespace std;

bool Isip(string s)
{
    int i=0;
    for(int j=0;j<s.length();j++)
    {
        if(s[j]=='.'||j==s.length()-1)
        {
            int temp=stoi(s.substr(i,j));
            i=j+1;
            if(temp>255||temp<0)
            {
                return false;
            }
        }
    }
    return true;
}

int main() {
    string s;
    while(cin>>s)
    {
        if(Isip(s))cout<<"Yes!"<<endl;
        else cout<<"No!"<<endl;
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

白火同学:大二有这水平很牛了,可以适当对关键信息加粗一点,比如关键技术、性能指标之类的。
点赞 评论 收藏
分享
06-05 19:46
已编辑
武汉大学 后端
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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