题解 | #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