华中农业大学校赛--c The Same Color

本文介绍了一个简单的程序设计问题——根据特定规则将不同颜色的球分组,并计算两组球的数量乘积。通过示例解释了问题背景及输入输出样例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem C: The Same Color

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 993  Solved: 595
[Submit][Status][Web Board]

Description

 

   Diao Yang has many balls with different colors. Today he wants to divide his balls into two groups. But he does not know how to divide. Then Diao Ze gives him a suggestion: first you choose a ball and put it into the first group. Then from the second ball, if the color of the ball is same to the last ball you has chosen, then you put the ball into the other group. Otherwise you put the ball into the same group with the last ball. Diao Yang thinks it is OK.

 

   Then the problem is, Diao Yang wants to know the product of the number of two groups’ balls. Can you help him?

Input

 

   The first line contains an integer T, indicating the number of test cases.

   In each test case, there are several lines, each line contains only one string with lowercas, indicating the color of the ball Diao Yang has chosen currently. Diao Yang will stop choosing when the string is equal to “END”. Note that the string “END” does not mean a color.

   You can assume that there are at most 100 lines in each test case and each string has at most 10 letters.

 

Output

 

   For each test case, output the answer in a line.

Sample Input

3
yellow
yellow
pink
red
red
green
END
blue
black
purple
purple
END
rose
orange
brown
white
END

Sample Output

9
3
0

HINT

 

 


 


In the first test case, the color of the first group’s balls are yellow, red, green, 3 balls in total. The color of the second group’s balls are yellow, pink, red, 3 balls in total too. So the product is 3×3=9.


   In the second test case, the answer is 3×1=3 and in the third test case the answer is 4×0=0.

 

 

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<map>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        int g[2];
        g[0]=1;
        g[1]=0;
        char a[12];
        char b[12];
        scanf("%s",b);
        int t=0;
        if(strcmp(b,"END")==0)
        {
            printf("0\n");
            continue;
        }
        scanf("%s",a);
        while(strcmp(a,"END")!=0)
        {
            if(strcmp(a,b)==0)
            {
                t=1-t;
                g[t]++;
            }
            else
            {

                g[t]++;
            }
            strcpy(b,a);
            scanf("%s",a);
        }
        printf("%d\n",g[0]*g[1]);
    }
    return 0;
}
View Code

水题,只是考虑第一个颜色就是END就可以了。wa惨了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值