zoukankan      html  css  js  c++  java
  • codeforces 758 B

    给你一个字符串

    气球有5种状态 R B Y G  !

    每4个气球状态都是  RBYG里分别一种

    最后求出 ! 里面 RBYG 的个数

    4是循环结 

    #include<stdio.h>
    #include<algorithm>
    #include<string.h>
    #include<math.h>
    #include<set>
    #include<string>
    
    using namespace std;
    typedef long long LL;
    
    #define inf  10000000000000
    #define MAXN 100010
    
    char str[MAXN];
    bool vis[MAXN];
    
    int r,y,b,g;
    
    int main()
    {
        while(scanf("%s",&str)!=EOF)
        {
            int len=strlen(str);
            memset(vis,0,sizeof(vis));
            for(int i=0;i<len;i++)
                if(str[i]=='!')
                    vis[i]=1;
    
            for(int i=0;i<len;i++)
            {
                if(str[i]!='!')
                {
                    int j,k;
                    j=k=i;
    
                    while(j+4<len)
                    {
                        str[j+4]=str[i];
                        j+=4;
                    }
                    while(k-4>=0)
                    {
                        str[k-4]=str[i];
                        k-=4;
                    }
                }
            }
            r=b=g=y=0;
    
            for(int i=0;i<len;i++)
                if(vis[i]==1)
                {
                    if(str[i]=='R')
                        r++;
                    else if(str[i]=='B')
                        b++;
                    else if(str[i]=='G')
                        g++;
                    else
                        y++;
                }
            printf("%d %d %d %d
    ",r,b,y,g);
        }
        return 0;
    }
  • 相关阅读:
    软考相关试题
    qt中的toUtf8, toLatin1, Local8bit, toUcs4(转)
    qt的中文乱码问题
    《左耳听风》-ARTS-打卡记录-第八周
    杂题
    图论
    基础数据结构
    整除
    同余
    常用数学
  • 原文地址:https://www.cnblogs.com/cherryMJY/p/6428618.html
Copyright © 2011-2022 走看看