hzauoj The Same Color (模拟)
来源:互联网 发布:mac steam 游戏存档 编辑:程序博客网 时间:2024/06/16 03:36
Problem C: The Same Color
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 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
3yellowyellowpinkredredgreenENDblueblackpurplepurpleENDroseorangebrownwhiteEND
Sample Output
930
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<stdio.h>#include<string.h>#include<algorithm>#include<iostream>using namespace std;char s[30],c[30];int main(){int t,i,j;scanf("%d",&t);while(t--){int a=0,b=0;int tmp;memset(c,'\0',sizeof(c));while(scanf("%s",s)&&strcmp(s,"END")!=0){if(strcmp(s,c)==0){b++;tmp=a;a=b;b=tmp;}elsea++;strcpy(c,s);}printf("%d\n",a*b);}return 0;}
- hzauoj The Same Color (模拟)
- The Same Color
- The Same Color
- HZAU 1012 The Same Color
- Problem C: The Same Color
- Problem C: The Same Color
- poj1027--The Same Game(模拟)
- The Same Game-POJ1027模拟
- max submatrix which has all borders the same color.
- Problem C: The Same Color 水题 字符串处理
- poj1027 The Same Game (简单模拟题)
- POJ 1027 The Same Game 模拟题
- poj 1027 The Same Game(大模拟)
- poj 1027 The Same Game 模拟
- Make status bar the same color as activity's top color
- HDU 1556 Color the ball (模拟)
- Most NBA players support of the same color Obama is not the main reason
- POJ 1027 The Same Game棋盘游戏(模拟)
- 【MySql性能优化二】利用explain进行查询和分析sql语句
- 第1课:解密SparkStreaming另类实验及SparkStreaming本质解析
- UVA 10245 The Closest Pair Problem
- Http认证模式
- UI控件--自定义SeekBar样式
- hzauoj The Same Color (模拟)
- 哈理工OJ 1179 下山(DP+深搜)
- 关于“Error: "const char *" 类型的实参与 "LPCWSTR"类型的形参不兼容”错误的解决方案
- Android中各种奇葩,难解的Json
- C++虚基类的内存布局(上)
- 飞思卡尔高级驾驶员辅助系统(ADAS)解决方案
- 学习归幷排序
- 2016百度之星资格赛 C题
- 设置ssh免登录并设置别名