1.从键盘输入字符串1,再从键盘输入字符串2,求字符串2在字符串1中出现的次数
#include <stdio.h>
#define MAX 1000
int main()
{
int i = 0;
int j = 0;
int count = 0;
{
int i = 0;
int j = 0;
int count = 0;
char a[MAX];
char b[MAX];
char b[MAX];
printf("Please input string a:\n");
scanf("%s",a);
printf("Please input string b:\n");
scanf("%s",b);
while(a[i] != '\0')
{
if(a[i] == b[j])
{
while(b[j] != '\0')
{
i++;
j++;
break;
}
}
else
{
i++;
}
if(b[j] == '\0')
{
count++;
j = 0;
}
}
{
if(a[i] == b[j])
{
while(b[j] != '\0')
{
i++;
j++;
break;
}
}
else
{
i++;
}
if(b[j] == '\0')
{
count++;
j = 0;
}
}
printf("count = %d\n",count);
return 0;
}
}
2.n个人围成一圈,进行1-3循环报数,求最后剩下哪个人
#include <stdio.h>
#define MAX 1000
int main()
{
int i;
int num;
int temp;
int count = 0;
int a[MAX];
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)
{
a[i] = 0;
num--;
count = 0;
}
i++;
if(i == temp)
{
i = 0;
}
}
for(i = 0; i < temp; i++)
{
if(a[i] != 0)
{
printf("result = %d",a[i]);
}
}
return 0;
}