Home Article Practice c语言打字练习---

c语言打字练习---

2023-11-04 00:07  views:1021  source:yyyyomo    

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <iostream>
using namespace std;
void find(char *str1,char *str2);
int times(char *str1,char *str2);
int main(){
printf("devisor Huxinyue\nvision 1.0\n");
char str1[10001],str2[10001];
gets(str2);
gets(str1);
find(str1,str2);
int n;
n = times(str1,str2);
cout<<n<<endl;
}
void find(char *str1,char *str2){
int n = 0,flag=0;
char *p;
char *q;
while( *str2 != '\0')
{
p = str1;
q = str2;
while((*p == *q)&&(*p!='\0')&&(*q!='\0'))
{
p++;
q++;
}
if(*p=='\0')
{
printf("%d ",n+1);
flag++;
}
str2++;
n++;
}
if(flag==0){
printf("-1");}
printf("\n");
}
int times(char *str1,char *str2)
{
int n=0,s1,s2;
char *p=str2;
s1=strlen(str2);
s2=strlen(str1);
while(s1 >= s2)
{
str2=strstr(str2,str1);
if(str2 != 0)
{
n++;
str2=str2+s2;
}
else break;
s1=strlen(str2);
}
return n;
}



Disclaimer: The above articles are added by users themselves and are only for typing and communication purposes. They do not represent the views of this website, and this website does not assume any legal responsibility. This statement is hereby made! If there is any infringement of your rights, please contact us promptly to delete it.

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)