Sicily 9160. ESEJ

9160. ESEJ

Constraints

Time Limit: 1 secs, Memory Limit: 256 MB

Description

Mirko's latest homework assignment is writing an essay. However, he finds writing essays so boring that, after working for two hours, he realized that all he has written are N long words consisting entirely of letters A and B. Having accepted that he will never finish the essay in time, poor Mirko has decided to at least have some fun with it by counting nice words.
Mirko is connecting pairs of identical letters (A with A, B with B) by drawing arches above the word. A given word is nice if each letter can be connected to exactly one other letter in such a way that no two arches intersect. Help Mirko count how many words are nice.

Input

The first line of input contains the positive integer N (1 ≤ N ≤ 100), the number of words written down by Mirko.
Each of the following N lines contains a single word consisting of letters A and B, with length between 2 and 100 000, inclusive. The sum of lengths of all words doesn't exceed 1 000 000.

Output

The first and only line of output must contain the number of nice words.

Sample Input

3
ABAB
AABB
ABBA

Sample Output

2

Problem Source

2013年每周一赛第10场/COCI 2013.1

感觉跟那道夫妻匹配题很像:

发现用gets读字符串比scanf快;

#include <stdio.h>
#include <stack>
using namespace std;

int main() {
    int counter = 0, n;
    scanf("%d\n", &n);
    char temp[100001];
    while (n--) {
        stack<char> s;
        gets(temp);
        for (int i = 0; temp[i] != '\0'; i++) {
            if (s.empty()) {
                s.push(temp[i]);
            } else {
                if (temp[i] == s.top()) {
                    s.pop();
                } else {
                    s.push(temp[i]);
                }
            }
        }
        if (s.empty()) {
            counter++;
        }
    }
    printf("%d\n", counter);
    return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值