Problem C: The Same Color
来源:互联网 发布:java删除压缩文件 编辑:程序博客网 时间:2024/06/16 11:38
Problem C: The Same Color
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 983 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<math.h>char str[105][15];int main(){int a,b,T,flag;scanf("%d",&T);while(T--){int len=0;memset(str,0,sizeof(str));a=0,b=0;while(scanf("%s",str[len])){if(strcmp(str[len],"END")==0)break;if(len==0){a++;flag=1;} else{if(strcmp(str[len],str[len-1])==0){if(flag==1){b++;flag=2;}else{a++;flag=1;}}else{if(flag==1){a++;}else{b++;}}}len++;}printf("%d\n",a*b);}return 0;}
- Problem C: The Same Color
- Problem C: The Same Color
- Problem C: The Same Color 水题 字符串处理
- The Same Color
- The Same Color
- HZAU 1012 The Same Color
- hzauoj The Same Color (模拟)
- Problem F: The Nearest Same Chocolate
- max submatrix which has all borders the same color.
- Make status bar the same color as activity's top color
- Problem when launching several jobs at the same time
- hit 1001 a+b problem (the same as hdu,poj)
- Most NBA players support of the same color Obama is not the main reason
- Ch8.6: write a method to paint-fill a closed ring with the same color
- Swift and Objective-C in the Same Project
- Dominant Color Problem Records
- Problem When use "Custom Editor" and "Property Drawers" The Same Time
- just the same和all the same
- 编程学习建议
- Docker学习一(安装docker并构建一个可ssh登录的镜像)
- Elasticsearch安装与测试验证详解
- AJAX工作原理及其优缺点
- WIN10 VBOX UBUNTU 网络访问不了
- Problem C: The Same Color
- wxPython & PyQT
- Git常用操作
- java学习地图
- Hadoop map与reduce数量
- CodeForces 510B Fox And Two Dots(DFS)
- 修改oracle数据库用户名及密码的方法
- 什么是Dubbo
- Problem H: Eat Candy