Codeforces721 A. One-dimensional Japanese Crossword (水题)
来源:互联网 发布:mac安装python2.7 编辑:程序博客网 时间:2024/05/22 10:49
题目连接:http://codeforces.com/contest/721/problem/A
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized a × b squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents how many groups of black squares there are in corresponding row or column, and the integers themselves represents the number of consecutive black squares in corresponding group (you can find more detailed explanation in Wikipedia https://en.wikipedia.org/wiki/Japanese_crossword).
Adaltik decided that the general case of japanese crossword is too complicated and drew a row consisting of n squares (e.g. japanese crossword sized 1 × n), which he wants to encrypt in the same way as in japanese crossword.
Help Adaltik find the numbers encrypting the row he drew.
The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the length of the row. The second line of the input contains a single string consisting of n characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew).
The first line should contain a single integer k — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain k integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right.
3BBW
12
5BWBWB
31 1 1
4WWWW
0
4BBBB
14
13WBBBBWWBWBBBW
34 1 3
The last sample case correspond to the picture in the statement.
题目大意:找多少段连续的‘B’。
解题思路:直接模拟。
/* ***********************************************┆ ┏┓ ┏┓ ┆┆┏┛┻━━━┛┻┓ ┆┆┃ ┃ ┆┆┃ ━ ┃ ┆┆┃ ┳┛ ┗┳ ┃ ┆┆┃ ┃ ┆┆┃ ┻ ┃ ┆┆┗━┓ 马 ┏━┛ ┆┆ ┃ 勒 ┃ ┆ ┆ ┃ 戈 ┗━━━┓ ┆┆ ┃ 壁 ┣┓┆┆ ┃ 的草泥马 ┏┛┆┆ ┗┓┓┏━┳┓┏┛ ┆┆ ┃┫┫ ┃┫┫ ┆┆ ┗┻┛ ┗┻┛ ┆************************************************ */#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <bitset>using namespace std;#define rep(i,a,b) for (int i=(a),_ed=(b);i<=_ed;i++)#define per(i,a,b) for (int i=(b),_ed=(a);i>=_ed;i--)#define pb push_back#define mp make_pairconst int inf_int = 2e9;const long long inf_ll = 2e18;#define inf_add 0x3f3f3f3f#define mod 1000000007#define LL long long#define ULL unsigned long long#define MS0(X) memset((X), 0, sizeof((X)))#define SelfType intSelfType Gcd(SelfType p,SelfType q){return q==0?p:Gcd(q,p%q);}SelfType Pow(SelfType p,SelfType q){SelfType ans=1;while(q){if(q&1)ans=ans*p;p=p*p;q>>=1;}return ans;}#define Sd(X) int (X); scanf("%d", &X)#define Sdd(X, Y) int X, Y; scanf("%d%d", &X, &Y)#define Sddd(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())#define all(a) a.begin(), a.end()#define mem(x,v) memset(x,v,sizeof(x))typedef pair<int, int> pii;typedef pair<long long, long long> pll;typedef vector<int> vi;typedef vector<long long> vll;inline int read(){int ra,fh;char rx;rx=getchar(),ra=0,fh=1;while((rx<'0'||rx>'9')&&rx!='-')rx=getchar();if(rx=='-')fh=-1,rx=getchar();while(rx>='0'&&rx<='9')ra*=10,ra+=rx-48,rx=getchar();return ra*fh;}//#pragma comment(linker, "/STACK:102400000,102400000")int ans[100];int main(){//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);string s;int n;n = read();cin>>s;int cnt = 0;for(int i=0;i<s.size();i++) { int tot = 0; while(s[i]=='B' && i<s.size()) { i++; tot++; } if(tot)ans[cnt++] = tot; } if(cnt) { cout<<cnt<<endl; for(int i=0;i<cnt;i++) { cout<<ans[i]; if(i!=cnt-1)cout<<" "; else cout<<endl; } } else cout<<0<<endl;return 0;}
- Codeforces721 A. One-dimensional Japanese Crossword (水题)
- A. One-dimensional Japanese Crossword
- CodeForces 721A One-dimensional Japanese Crossword(第三场)
- Codeforce 721A One-dimensional Japanese Crossword
- CodeForces 721A One-dimensional Japanese Crossword
- Codeforces 721A-One-dimensional Japanese Crossword
- Codeforces #374(Div.2)A. One-dimensional Japanese Crossword【模拟】水题
- 【76.57%】【codeforces 721A】One-dimensional Japanese Crossword
- Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crossword —— 基础题
- AT1 one-dimensional objects
- bzoj4688 One-Dimensional
- UVALive 6184 One-Dimensional Cellular Automaton(矩阵加速)
- CF One-Dimensional Battle Ships(set运用)
- 567D One-Dimensional Battle Ships(set)
- [数据结构]One-Dimensional Life Game
- One-Dimensional Battle Ships CodeForces
- ZOJ--3992--One-Dimensional Maze
- Japanese
- 3G模块测试脚本
- 微信小程序
- MyEclipse精简优化
- [心得]基于vim打造高级代码开发环境
- Java学习总结第十二天Java类与对象
- Codeforces721 A. One-dimensional Japanese Crossword (水题)
- STM32 GPIO设置
- STM32F407 VS STM32F103 主要功能及资源对比
- spring MVC3.x和JDK 8不兼容问题
- Codeforces712 B. Passwords (贪心水题)
- java内部类的分类和创建
- redhat tftp server配置
- POJ 2481 Cows (树状数组)
- 更新Xcode后遇到的坑