首页 > 试题广场 >

protocal data parse

[编程题]protocal data parse
  • 热度指数:256 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
SIP is an important protcoal of IP Phone, it could be configed with some special information to display. huntPilot URI is one kind of, and  IP phone will catch and display alert name for third party calling if there is huntPilotName configed in  huntPilot URI.

HuntPilot URI Samples:
huntpiloturi = "<sip:10000@172.16.130.42>;"                                                 alertName=
huntpiloturi = " "<sip:10000@172.16.130.42>;                                                alertName=
huntpiloturi = "huntpilotname<sip:10000@172.16.130.42>";                           alertName=huntpilotname
huntpiloturi = "huntpilotname”<sip:10000@172.16.130.42>;                           alertName=huntpilotname
huntpiloturi = "%22huntpilotname%22<sip:10000@172.16.130.42>";            alertName=huntpilotname
huntpiloturi = "%22huntpilot%22name%22"<sip:10000@172.16.130.42>;     alertName=huntpilot%22name

输入描述:
String with URI information


输出描述:
String
示例1

输入

"Cisco<sip:10000@172.16.130.42>"

输出

Cisco
示例2

输入

"%22Cisco%22"<sip:10000@172.16.130.42>

输出

Cisco
int main()
{
    char vs[1024];
    char* ans;
    string str;
    while (cin >> str)
    {
        int len = str.find("<");
        if (len < 0) len = str.length();
        len--;
        str.copy(vs, len, 1);
        if (vs[len - 1] == '\"')
            vs[--len] = '\0';
        else vs[len] = '\0';
 
        ans = vs;
        if (len >= 5)
        {
            if (vs[len - 1] == '2' && vs[len - 2] == '2' && vs[len - 3] == '%')
            {
                ans = vs + 3;
                vs[len - 3] = '\0';
            }
        }
 
        cout << ans << endl;
    }
 
    return 0;
}

发表于 2020-03-08 20:21:16 回复(0)
//正则表达式匹配一下
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        Pattern pattern = Pattern.compile("\"*(%22)?(\\w+(%22)*\\w+)(%22)?\"*(<\\w+:\\w+@\\w+.\\w+.\\w+.\\w+>)*\"*");
        Matcher matcher = pattern.matcher(s);
        while (matcher.find()) {
            System.out.println(matcher.group(2));
        }
    }
}

发表于 2020-04-17 16:04:41 回复(1)
uri = input()
name = uri[1: uri.find('<')]
if '%22' in name:
    name = name[name.find('%22')+3 : name.rfind('%22', 3)]
if name == ''&nbs***bsp;name == ' \"':
    print()
elif name[-1] == '\"':
    print(name[:-1])
else:
    print(name)

发表于 2022-09-20 16:03:02 回复(0)
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string str;
    getline(cin,str);
    int len=str.size();
    string s;
    for(int i=0;i<len;++i)
    {
        if(str[i]=='<')
            break;
        if(str[i]>='A'&&str[i]<='z')
        {
            s+=str[i];
        }
        else if(str[i]!='<')
        {
            int j=i;
            if(!s.empty())
            {
                while(j<len&&str[j]!='<')
                {
                    if(str[j]>='A'&&str[j]<='z')
                        break;
                    ++j;
                }
                if(j<len&&str[j]!='<')
                {
                    j=i;
                    while(str[j]<'A'||str[j]>'z')
                    {
                        s+=str[j];
                        ++j;
                    }
                }
                i=j-1;
            }
        }
    }
    int ll=s.size();
    for(int i=0;i<ll;++i)
        cout<<s[i];
    return 0;
}
发表于 2020-09-04 22:12:34 回复(0)
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        String res = "";
        int i=0;
        for(; i<str.length(); i++){
            if(str.charAt(i)=='<')
                break;
        }
        int start = 0;
        if(str.charAt(0)=='"')
            start = 1;
        if(str.charAt(i-1)=='"')
            i = i - 1;
        if(start>=i){
            System.out.println("");
            return;
        }
        str = str.substring(start, i);
        if(str.length()<6) {
            System.out.println(str);
            return;
        }
        boolean flag = false;
        if(str.charAt(0)=='%' && str.charAt(1)=='2' && str.charAt(2)=='2') {
            flag = true;
            start = 3;
        }
        int l = str.length();
        if(flag && str.charAt(l-1)=='2' && str.charAt(l-2)=='2' && str.charAt(l-3)=='%') {
            i = l-3;
        }
        else
            flag = false;
        if(flag)
            str = str.substring(start, i);
 
        System.out.println(str);
    }
}

发表于 2020-03-05 23:02:18 回复(0)