The Same Color

1012: The Same Color

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 3   Solved: 2
[ 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


#include<stdio.h>
#include<iostream>
using namespace std;
#include<string.h>
char s[200][200];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(s,0,sizeof(s));//清零要写
        int l;
        int k=0;
        int y=0;
        int i,j;
//        while(~scanf("%s",s[l]))//第一种输入法//前面先定义l=0;
//        {
//            if(s[l][0]=='E'&&s[l][1]=='N'&&s[l][2]=='D')
//                break;
//            l++;
//        }
        for(l=0; ; l++)//第二种输入法
        {
            scanf("%s",s[l]);//l++;
            if(s[l][0]=='E'&&s[l][1]=='N'&&s[l][2]=='D')
            {
                break;
            }

        }
        int h=0;
        for(i=0; i<l; i++)
        {
            if(s[i][0]==s[i-1][0]&&s[i][1]==s[i-1][1]&&s[i][2]==s[i-1][2]&&s[i][3]==s[i-1][3]&&s[i][4]==s[i-1][4]&&s[i][5]==s[i-1][5])
            {
                if(h==0)
                {
                    y++;
                    h=1;
                }
                else
                {
                    k++;
                    h=0;
                }
            }
            else
            {
                if(h==0)
                {
                    k++;
                    h=0;
                }
                else
                {
                    y++;
                    h=1;
                }
            }
        }
        printf("%d\n",k*y);
    }
}

 

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值