LightOJ 1109 -1354 - IP Checking(字符串的处理)

题目大意:

  这题的意思就是说,给两个字符串,一个字符串中的数字是用10进制表示的,一个字符串的数字是用2进制表示的,看看十进制和二进制是否对应。

解题思路:

  处理在‘.‘上。。。。

代码:

 1 # include<cstdio>
 2 # include<iostream>
 3 # include<cstring>
 4 # include<cmath>
 5
 6 using namespace std;
 7
 8 # define MAX 50
 9
10 char s1[MAX];
11 char s2[MAX];
12 int n1,n2,n3,n4;
13 string str;
14
15 int check()
16 {
17     int i = 0, temp = 0;
18     while ( str[i]!=‘.‘ )
19     {
20         temp*=2;
21         temp+=(str[i]-‘0‘);
22         i++;
23     }
24     if ( temp!= n1 )
25         return 0;
26     i++; temp = 0;
27     while ( str[i]!=‘.‘ )
28     {
29        temp*=2;
30        temp+=(str[i]-‘0‘);
31        i++;
32     }
33     if ( temp!=n2 )
34         return 0;
35
36     i++; temp = 0;
37     while ( str[i]!=‘.‘ )
38     {
39         temp*=2;
40         temp+=(str[i]-‘0‘);
41           i++;
42     }
43     if ( temp!=n3 )
44         return 0;
45     i++; temp = 0;
46     while ( str[i]!=‘\0‘ )
47     {
48         temp*=2;
49         temp+=(str[i]-‘0‘);
50           i++;
51     }
52     if ( temp!=n4 )
53         return 0;
54     return 1;
55 }
56
57
58 int main(void)
59 {
60     int icase = 1;
61     int t;cin>>t;
62     while ( t-- )
63     {
64         scanf("%d.%d.%d.%d",&n1,&n2,&n3,&n4);
65         cin>>str;
66         int flag = check();
67         printf("Case %d: ",icase++);
68         if ( flag )
69             cout<<"Yes"<<endl;
70         else
71             cout<<"No"<<endl;
72     }
73
74     return 0;
75 }
时间: 2024-08-25 03:21:59

LightOJ 1109 -1354 - IP Checking(字符串的处理)的相关文章

LightOJ - 1354 IP Checking

IP Checking Time Limit: 2000MS   Memory Limit: 32768KB   64bit IO Format: %lld & %llu Submit Status Description An IP address is a 32 bit address formatted in the following way a.b.c.d where a, b, c, d are integers each ranging from 0 to 255. Now you

lightoj-1354 - IP Checking(水题)

1354 - IP Checking PDF (English) Statistics ForumTime Limit: 2 second(s) Memory Limit: 32 MBAn IP address is a 32 bit address formatted in the following way a.b.c.d where a, b, c, d are integers each ranging from 0 to 255. Now you are given two IP ad

SQL Server使用PARSENAME函数来处理IP地址字符串

IP V4地址是用3个点分隔的字符串,有时候需要在数据库中进行处理,比如判断IP地址是否有效等. 通常想到的方法是自己写个函数,比如利用CHARINDEX.SUBSTRING等函数组合来获取IP地址的各个部分,然后处理. SQL Server用来表示对象的时候通常采取 架构名.对象名.数据库名.架构名.对象名.链接服务器名.数据库名.架构名.对象名 等方式 比如dbo.tablename.master.dbo.tablename.[192.168.1.100].master.dbo.tablen

IP地址字符串与BigInteger的转换

/**  * Copyright (c) 2010, 新浪网支付中心  *      All rights reserved.  *  * Java IP地址字符串与BigInteger的转换,  * 支持IPv6  *  */ import java.math.BigInteger; import java.net.InetAddress; import java.net.UnknownHostException; /**  * IP转换大数进行比较工具  *  * @author [emai

获取远程IP、字符串解析

public class StringUtil { private static final Pattern IPV4_PATTERN = Pattern.compile( "^(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}$"); private static final Pattern IPV6_STD_PATTERN = Pattern.compile( "^(?:[0

LightOJ 1109 - False Ordering (因式分解)

1109 - False Ordering   PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB We define b is a Divisor of a number a if a is divisible by b. So, the divisors of 12 are 1, 2, 3, 4, 6, 12. So, 12 has 6 divisors. Now you have to ord

LightOJ 1044 Palindrome Partitioning(简单字符串DP)

A palindrome partition is the partitioning of a string such that each separate substring is a palindrome. For example, the string "ABACABA" could be partitioned in several different ways, such as {"A","B","A","

将IP地址字符串形式拆成四个整数形式

/* * File: main.c * Author: liutingting */ #include<stdio.h> #include<stdlib.h> #include<Winsock2.h> #include<string.h> #include<time.h> #include <Ws2tcpip.h> #pragma comment(lib,"WS2_32.lib") int main(int arg

lightoj Beginners Problems

很多以前写的丑代码 1000 - Greetings from LightOJ #include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int a,b,n,Case; scanf("%d",&n); Case=0; while(Case++,n--) { scanf("%d%d",&