C语言OJ项目参考(2874)包含B的字符串

    xiaoxiao2026-05-06  11

    2874: 包含B的字符串

    Description 输出n个字符串,把其中以包含字母B或b的字符串输出。 Input 第一行 n 第二行到第n+1行,每行一个字符串 Output 包含字母B或b的字符串 Sample Input** 6 Ada Bob Tom Brown Jobs Alice Sample Output Bob Brown Jobs

    参考解答:

    #include <stdio.h> int main() { int i,j,n,find; char s[80]; scanf("%d",&n); getchar(); //清除缓冲区 for(i=0;i<n;i++) { gets(s); j=0; find=0; while(s[j]!='\0') { if(s[j]=='B'||s[j]=='b') { find=1; break; } j++; } if(find) puts(s); } return 0; }
    最新回复(0)