DoubleLi

qq: 517712484 wx: ldbgliet

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
  4737 随笔 :: 2 文章 :: 542 评论 :: 1615万 阅读
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

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

 

 

 

  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.  
    }
posted on   DoubleLi  阅读(556)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2014-09-15 VNC的安装与配置
2014-09-15 (总结)CentOS Linux下VNC Server远程桌面配置详解
2014-09-15 在 Windows 下远程桌面连接 Linux - XManager 篇
2014-09-15 在 Windows 下远程桌面连接 Linux - VNC 篇
2014-09-15 Debian上安装TightVNC Server
2014-09-15 Install TightVNC Server in RHEL/CentOS and Fedora to Access Remote Desktops
2013-09-15 C++实现线程池 .
点击右上角即可分享
微信分享提示