首页 技术 正文
技术 2022年11月20日
0 收藏 563 点赞 3,296 浏览 860 个字

直接上代码(不要直接拷贝,中间少了一行啊):

  1.  #include <string>
  2.  #include <iostream>
  3.  using namespace std;
  4.  int shu[4]={0};
  5.  int IPtoINT(string s){
  6.  int i,a=0,c=0,p=0;
  7.  for(i=0;i<s.length();i++)
  8.  {
  9.  if(s[i]!=’.’)
  10.  {
  11.  a=a*10+(s[i]-‘0’);
  12.  }else{
  13.  if(a>=0&&a<=255)
  14.  {
  15.  shu[p++]=a;
  16.  c++;
  17.  }else
  18.  {//cout<<“NO”<<endl;
  19.  return 0;}
  20.   
  21.  }
  22.  }
  23.  if(c!=3)
  24.  {//cout<<“NO”<<endl;
  25.  return 0;}
  26.  else
  27.  {if(a>=0&&a<=255)
  28.  {
  29.  shu[p++]=a;
  30.  }else
  31.  {//cout<<“NO”<<endl;
  32.  return 0;}
  33.   
  34.  }
  35.  //cout<<“YES”<<endl;
  36.  return 1;
  37.  }
  38.  void INTtoIP(long s)
  39.  {
  40.  shu[0]=s&255;
  41.  shu[1]=(s&(255*256))/256;
  42.  shu[2]=(s&(255*256*256))/(256*256);
  43.  shu[3]=(s&(255*256*256*256))/(256*256*256);
  44.  }
  45.  void main(){
  46.  string ips;
  47.  long ipint,stoint=0;
  48.  int i;
  49.  cin>>ips;
  50.  cin>>ipint;
  51.  if(IPtoINT(ips))
  52.  {
  53.  for(i=0;i<4;i++)
  54.  stoint=stoint*256+shu[i];
  55.  cout<<stoint<<endl;
  56.  }
  57.  INTtoIP(ipint);
  58.  if(shu[0]<256&&shu[1]<256&&shu[2]<256&&shu[3]<256)
  59.  {
  60.  cout<<shu[3]<<‘.'<<shu[2]<<‘.'<<shu[1]<<‘.'<<shu[0]<<endl;
  61.  }
  62.  }
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,941
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,465
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,280
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,094
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,728
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,765