Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crossword —— 基础题
题目链接:http://codeforces.com/contest/721/problem/A
1 second
256 megabytes
standard input
standard output
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.
The
example of encrypting of a single row of 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.
3
BBW
1
2
5
BWBWB
3
1 1 1
4
WWWW
0
4
BBBB
1
4
13
WBBBBWWBWBBBW
3
4 1 3
The last sample case correspond to the picture in the statement.
题解:
虽然是一道很基础的题目,但是却清晰了我对类似情况的写法, 值得记录一下。
关键代码:
if(a[i]=='B')
{
if(i==0 || a[i-1]=='W') k++;
s[k]++;
}
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#include <algorithm>
using namespace std;
#define ms(a, b) memset((a), (b), sizeof(a))
#define eps 0.0000001
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+7;
const int maxn = 100+10; int n;
char a[maxn];
int k, s[maxn]; void init()
{
scanf("%d",&n);
scanf("%s",a);
ms(s,0);
k = 0;
} void solve()
{
int cnt = 1;
for(int i = 0; i<n; i++)
{
if(a[i]=='B')
{
if(i==0 || a[i-1]=='W') k++;
s[k]++;
}
} printf("%d\n",k);
for(int i = 1; i<=k; i++)
printf("%d ",s[i]);
putchar('\n');
} int main()
{
// int T;
// scanf("%d",&T);
// while(T--)
{
init();
solve();
}
return 0;
}
Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crossword —— 基础题的更多相关文章
- Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)
Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...
- Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crosswor 水题
A. One-dimensional Japanese Crossword 题目连接: http://codeforces.com/contest/721/problem/A Description ...
- 拓扑序+dp Codeforces Round #374 (Div. 2) C
http://codeforces.com/contest/721/problem/C 题目大意:给你有向路,每条路都有一个权值t,你从1走到n,最多花费不能超过T,问在T时间内最多能访问多少城市? ...
- Codeforces Round #374 (Div. 2) D. Maxim and Array 贪心
D. Maxim and Array 题目连接: http://codeforces.com/contest/721/problem/D Description Recently Maxim has ...
- Codeforces Round #374 (Div. 2) C. Journey DP
C. Journey 题目连接: http://codeforces.com/contest/721/problem/C Description Recently Irina arrived to o ...
- Codeforces Round #374 (Div. 2) B. Passwords 贪心
B. Passwords 题目连接: http://codeforces.com/contest/721/problem/B Description Vanya is managed to enter ...
- Codeforces Round #374 (Div. 2) D. Maxim and Array —— 贪心
题目链接:http://codeforces.com/problemset/problem/721/D D. Maxim and Array time limit per test 2 seconds ...
- Codeforces Round #374 (Div. 2) C. Journey —— DP
题目链接:http://codeforces.com/contest/721/problem/C C. Journey time limit per test 3 seconds memory lim ...
- Codeforces Round #374 (Div. 2) B. Passwords —— 基础题
题目链接:http://codeforces.com/contest/721/problem/B B. Passwords time limit per test 2 seconds memory l ...
随机推荐
- springboot idea激活指定profile
多Profile文件 配置文件编写的时,可以是application-{profile}.properties/yml,默认使用application.properties的配置: 激活指定profi ...
- jsp、freemarker、velocity 的区别
在java领域,表现层技术主要有三种:jsp.freemarker.velocity. 一.jsp是大家最熟悉的技术:优点:1.功能强大,可以写java代码2.支持jsp标签(jsp tag)3.支持 ...
- mac安装.net core
https://www.microsoft.com/net/core#macos Install for macOS 10.11 or higher (64 bit) 1 Install pre-re ...
- JS里面的call, apply以及bind
参考了这篇文章:http://www.tuicool.com/articles/EVF3Eb 给几个例子 function add(a,b) { alert(a+b); } function sub( ...
- CSRF攻击 & XSS攻击
之前有几篇文章写了 SQL注入类问题: http://www.cnblogs.com/charlesblc/p/5987951.html (介绍) http://www.cnblogs.com/cha ...
- Android--------------几个ADB经常使用命令
1. 显示当前执行的所有模拟器: adb devices 2. 安装应用程序: adb install -r 123.apk 3. 获取模拟器中的文件: adb pull &l ...
- css3 - 动态伪类
动态伪类分为以下几种: 1. hover(经过) 2. active(点击后) 3. focus(聚焦) - input专用 4. visited(访问后) 使用:
- Android Design Support Library概览
尊重劳动成果.转载请注明出处:http://blog.csdn.net/growth58/article/details/47972467 关注新浪微博:@于卫国 邮箱:yuweiguocn@gmai ...
- const、typedef 、 define总结
constkeyword const=read only,修饰的为仅仅读变量而不是常量.const修饰的变量不能用作数组的维数也不能放在switch语句的case:之后. 主要作用有: 1.通过把不希 ...
- MySQL:unknown variable 'master-host=masterIP' [ERROR] Aborting
<span style="font-size:18px;">120401 15:45:44 [ERROR] C:\Program Files\MySQL\MySQL S ...