c++如何巧妙变为c,青高收捷达
#include<iostream>
using namespace std;
int main()
{
string str1,str2;
int n;
cin>>n;
while(n--)
{
cin>>str1>>str2;
int find=str1.find(str2);
if(find!=string::npos) cout<<"Found!"<<endl;
else cout<<"not Found!"<<endl;
}
}
供参考:
#include <stdio.h>
#include <string.h>
#define MAXS 256
char* search(char* s, char* t);
int main()
{
int n;
char s[MAXS] = { 0 }, t[MAXS] = {0}, * pos;
scanf("%d", &n);
getchar();
while (n--) {
gets(s);
gets(t);
pos = search(s, t);
if (pos != NULL)
printf("Found!\n");
else
printf("Not Found!\n");
}
return 0;
}
char* search(char* s, char* t)
{
int i, j, k, flg;
char* pos = NULL;
for (i = 0, flg = 1; flg && s[i] != '\0'; i++)
for (j = i, k = 0; t[k] == s[j]; k++, j++)
if (t[k + 1] == '\0') { pos = s + i; flg = 0; break; }
return pos;
}
#include <stdio.h>
#include <string.h>
int main()
{
char s1[80],s2[80];
int n;
scanf("%d",&n);
if (n<0) n=-n;
while (n--) {
fgets(s1,80,stdin);
fgets(s2,80,stdin);
char *p=strstr(s1,s2);
if (p) printf("Found!"\n");
else printf("not Found!\n");
}
return 0;
}