2017 Multi-University Training Contest

来源:互联网 发布:社交软件英文怎么说 编辑:程序博客网 时间:2024/06/07 05:53

Two strings

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 520    Accepted Submission(s): 195


Problem Description
Giving two strings and you should judge if they are matched.
The first string contains lowercase letters and uppercase letters.
The second string contains lowercase letters, uppercase letters, and special symbols: “.” and “*”.
. can match any letter, and * means the front character can appear any times. For example, “a.b” can match “acb” or “abb”, “a*” can match “a”, “aa” and even empty string. ( “*” will not appear in the front of the string, and there will not be two consecutive “*”.
 

Input
The first line contains an integer T implying the number of test cases. (T≤15)
For each test case, there are two lines implying the two strings (The length of the two strings is less than 2500).
 

Output
For each test case, print “yes” if the two strings are matched, otherwise print “no”.
 

Sample Input
3aaa*abba.*abbaab
 

Sample Output
yesyesno
 
题目大意:问给出的正则表达式能否匹配文本

解题思路:c++regex   注意.*不能匹配ab

这个真不会呀啊啊啊啊啊啊 = =

#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <string>#include <regex>using namespace std;const int MAXN = 2600;string s, p;int main(){    int T;    cin >> T;    while (T--)    {        cin >> s >> p;        string s1 = ".*";        string s2 = "(a*|b*|c*|d*|e*|f*|g*|h*|i*|j*|k*|l*|m*|n*|o*|p*|q*|r*|s*|t*|u*|v*|w*|x*|y*|z*"                    "|A*|B*|C*|D*|E*|F*|G*|H*|I*|J*|K*|L*|M*|N*|O*|P*|Q*|R*|S*|T*|U*|V*|W*|X*|Y*|Z*)";        auto pos = p.find(s1);        while (pos != string::npos)        {            p.replace(pos, 2, s2);            pos = p.find(s1, pos + 157);        }        regex pat(p);        if (regex_match(s, pat))        {            cout << "yes" << endl;        }        else        {            cout << "no" << endl;        }    }    return 0;}
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 电脑内存不够用怎么办 海信电视存储空间不足怎么办 支付宝学校没有怎么办 支付宝没有学历怎么办 华为p9gps信号弱怎么办 小米手机wifi慢怎么办 小米wifi网速慢怎么办 华为mate9网络差怎么办 大王卡信号差怎么办 华为P9Plus忘记密码怎么办 华为手机音质差怎么办 三星c5手机发烫怎么办 华为手机老卡怎么办 小米手机慢卡怎么办 华为指纹识别不灵敏了怎么办 金立手机信号不好怎么办 手机边框坏了怎么办 手机保护膜划了怎么办 车膜贴的有气泡怎么办 手机膜进气泡怎么办 贴的手机膜翘角怎么办 全屏膜出现气泡怎么办 手机膜的气泡怎么办 透明手机壳气泡怎么办 钢化膜边缘有气泡怎么办 贴钢化膜边缘有气泡怎么办 钢化膜边上有泡泡怎么办 贴钢化膜周边有气泡怎么办 钢化膜里面有气泡怎么办 手机保护膜破了怎么办 手机触摸屏没反应怎么办 苹果手机触屏坏了怎么办 手机边缘有气泡怎么办 手机膜有空气怎么办 电脑膜有气泡怎么办 汽车贴膜起泡怎么办 汽车玻璃膜用久了起泡怎么办 车窗玻璃膜起泡怎么办 新车贴膜气泡怎么办 贴手机钢化膜有灰尘怎么办 戒指砖石掉了怎么办