【暑假测试2】D ACdream 1125 ACfun-字典序(水)

来源:互联网 发布:苹果远程抹掉数据恢复 编辑:程序博客网 时间:2024/05/22 19:13

思路


算出一个字符串中最多有几个连续的 A (假设 n 个),然后输出 n + 1 个 ‘A’。


代码

#include <stdio.h>#include <string.h>int main() {    char str[100];    int count, max_count;    int n, len, i, now;    scanf("%d", &n);    while ( n-- ){        scanf("%s", str);        len = strlen(str);        count = max_count = 0;        for ( i = 0; i < len; i++){            if(str[i] == 'A'){                count++;                max_count = ( count > max_count) ? count : max_count;            } else {                count = 0;            }        }        for (i = 0; i < max_count + 1; i++){            printf("A");        }        printf("\n");    }    return 0;}


0 0
原创粉丝点击