字符串练习18_验证子串

来源:互联网 发布:管家婆软件怎么样 编辑:程序博客网 时间:2024/06/06 03:34
/*Name: 18_验证子串Copyright: Author: Date: 01-09-17 22:06Description: 18_验证子串查看 提交 统计 提问总时间限制: 1000ms 内存限制: 65536kB描述输入两个字符串,验证其中一个串是否为另一个串的子串。输入输入两个字符串,每个字符串占一行,长度不超过200且不含空格。输出若第一个串s1是第二个串s2的子串,则输出(s1) is substring of (s2) 否则,若第二个串s2是第一个串s1的子串,输出(s2) is substring of (s1) 否则,输出 No substring。样例输入abcdddncabca样例输出abc is substring of dddncabca*/#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N = 201;char S1[N],S2[N];int main() {gets(S1); gets(S2);if (strlen(S1) >= strlen(S2)){if (strstr(S1, S2) != NULL)cout << S2 << " is substring of " << S1 << endl;elsecout << "No substring" << endl;}else{if (strstr(S2, S1) != NULL)cout << S1 << " is substring of " << S2 << endl;elsecout << "No substring" << endl;}return 0;} 

原创粉丝点击