题解 | 数颜色

数颜色

https://www.nowcoder.com/practice/7f458453debe49c9a98f20f42d65ebf1

#include <stdio.h>

int main() 
{
    char S[100001] = "0";
    scanf("%s", S);
    char* ps = S;
    int countr = 0;
    int countg = 0;
    int countb = 0;
    while (*ps)
    {
       switch (*ps)
       {
        case 'R':
          countr++;
          break;
        case 'G':
          countg++;
          break;
        case 'B':
          countb++;
          break;         
       }
       ps++;
    }
    printf("(%d,%d,%d)", countr, countg, countb);
    return 0;
}

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务