欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > > 文章正文

18:验证子串,18验证

来源: javaer 分享于  点击 31505 次 点评:280

18:验证子串,18验证


原题链接

总时间限制: 
1000ms 
内存限制: 
65536kB
描述

输入两个字符串,验证其中一个串是否为另一个串的子串。

输入
输入两个字符串, 每个字符串占一行,长度不超过200且不含空格。
输出
若第一个串s1是第二个串s2的子串,则输出(s1) is substring of (s2) 
否则,若第二个串s2是第一个串s1的子串,输出(s2) is substring of (s1) 
否则,输出 No substring。
样例输入
abc
dddncabca
样例输出
abc is substring of dddncabca

源码

#include <iostream>
#include <cstring>
using namespace std;
int main()
{
    string s1, s2;
    cin >> s1 >> s2;
    if (s1.find(s2) != -1) cout << s2 << " is substring of " << s1 << endl;
    else if (s2.find(s1) != -1) cout << s1 << " is substring of " << s2 << endl;
    else cout << "No substring" << endl;
    return 0;
}


相关文章

    暂无相关文章

用户点评