shuoj 1086 字符串+进制改变

#include<iostream>
#include<string>
#include<cstring>
using namespace std;
struct network
{
    int add[4];
};
int convert(char *p)
{
    int ans=0;
    for(int i=0;i<strlen(p);i++)
    {
        ans=ans*10+(p[i]-'0');
    }
    return ans;
}
string And(int x,int y)
{
    string str="";
//    cout << x <<" "<< y << endl;
    for(int i=0;i<8;i++)
    {
        int a=x&1;
        x>>=1;
        int b=y&1;
        y>>=1;
        str+=('0'+(a&b));
    }
    return str;
}
int main()
{
    network ip;
    network subnet;
    char s[2][80];
    scanf("%s",s[0]);
    char *split=".";
    char *p=strtok(s[0],split);
    ip.add[0]=convert(p);
    for(int i=1;i<=3;i++)
    {
        ip.add[i]=convert(strtok(NULL,split));
    }
    scanf("%s",s[1]);
    p=strtok(s[1],split);
    subnet.add[0]=convert(p);
    for(int i=1;i<=3;i++)
    {
        subnet.add[i]=convert(strtok(NULL,split));
    }
    string str[4];
    for(int i=0;i<4;i++)
    {
        str[i]=And(ip.add[i],subnet.add[i]);
//        cout << str[i] << endl;
    }
    int times;
    scanf("%d",×);
    for(int i=1;i<=times;i++)
    {
        char intput[80];
        scanf("%s",intput);
        p=strtok(intput,split);
        int inttmp=convert(p);
        string strtmp=And(subnet.add[0],inttmp);
        if(strtmp!=str[0])
        {
            cout << "OUTER"<<endl;
            continue;
        }
        bool flag=true;
        for(int i=1;i<=3;i++)
        {
            p=strtok(NULL,split);
            inttmp=convert(p);
            strtmp=And(subnet.add[i],inttmp);
            if(strtmp!=str[i])
            {
                flag=false;
                break;
            }
        }
        if(flag) cout <<"INNER"<<endl;
        else cout <<"OUTER"<<endl;
    }
        

}



例一有误,改了一上午


strtok分割字符串 有点像python里的split,其他没啥了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值