题解 | #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")
腾讯云智研发成长空间 216人发布
查看3道真题和解析