当前位置:网站首页>1202 character lookup

1202 character lookup

2022-07-06 07:58:00 Zhanglilong 666

Title Description

 Find a specified character in a string , And output the number and position of the specified character in the string .

Input requirements

 On the first line, enter a string , On the second line, enter the character you want to find .

Output requirements

 The first line outputs the number of times the character has appeared in the string n,  Back n Line outputs the place where the character once appeared ( The position of occurrence is calculated according to the daily habit from 1 Start marker )

sample input

maybeyesmaybleno
m

sample output

2
1
9

#include<cstdio>
#include<cstring>
int main()
{
	char a[1006],k;
	int zll[1006]={0},len,i,sum=0,j=0;
	gets(a);
	len=strlen(a);
	scanf("%c",&k);
	for(i=0;i<len;i++){
		if(a[i]==k){
			sum++;
			zll[j]=i;
			j++;
		}
	}
	printf("%d\n",sum);
	for(i=0;i<j;i++){
		printf("%d\n",zll[i]+1);
	}
}

原网站

版权声明
本文为[Zhanglilong 666]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131849523218.html