【算法练习】字符串处理 IP地址

主要是输入处理哈

总感觉还有什么坑,

题目链接:https://www.nowcoder.com/practice/2359e23180194f99828f5cd9c764236a?tpId=40&tqId=21538&tPage=1&rp=1&ru=/ta/kaoyan&qru=/ta/kaoyan/question-ranking

ac代码

#include <iostream>
#include <stdio.h>
using namespace std;

int main(){
  int a,b,c,d;
  int n;
  char str[100];
    while(cin>>str){
   
   sscanf(str,"%d.%d.%d.%d",&a,&b,&c,&d);
   if((a>=0&&a<=255)&&(b>=0&&b<=255)&&(c>=0&&c<=255)&&(d>=0&&d<=255))
      cout<<"Yes!"<<endl;
   else
      cout<<"No!"<<endl;
    }
  return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_40760678/article/details/100086526