1输入字符母串,输入字符子串,统计出字符子串在字符母串中出现的次数
#include <stdio.h>
#define MAX_SIZE 1024
int main()
{
int i = 0;
int j = 0;
int temp = 0;
char a[MAX_SIZE];
char b[MAX_SIZE];
printf("please input a[] :n");
gets(a);
printf("please input b[]:n");
gets(b);
while(a[i] != ' ')
{
if(a[i] == b[j])
{
while(b[j] != ' ')
{
i++;
j++;
break;
}
}
else
{
i++;
}
if(b[j] == ' ')
{
temp++;
j = 0;
}
}
printf("the number is %dn",temp);
return 0;
}
2
#include <stdio.h>
#define MAX 1000
int main()
{
int i;
int num;
int temp;
int count = 0;
int a[MAX] = {0};
printf("Please input number:n");
scanf("%d",&num);
temp = num;
for(i = 0; i < num; i++)
{
a[i] = i + 1;
}
i = 0;
while(num > 1)
{
if(a[i] != 0)
{
count++;
}
if(count == 3)
{
num--;
a[i] = 0;
count = 0;
}
i++;
if(i == temp)
{
i = 0;
}
}
for(i = 0; i < temp; i++)
{
if(a[i] != 0)
{
printf("result = %dn",a[i]);
}
}
return 0;
}