Sicily 9160. ESEJ
来源:互联网 发布:淘宝医疗器械认证怎么弄 编辑:程序博客网 时间:2024/05/05 23:49
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
3ABABAABBABBA
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;}
- Sicily 9160. ESEJ
- sicily 9160 ESEJ
- Sicily 1027
- sicily 1007
- sicily 1795
- sicily 1036
- sicily 1419
- sicily 1889
- sicily 1684
- sicily 1686
- sicily 1004
- sicily 1135
- sicily 1152
- sicily 1151
- sicily 1002
- sicily 1156
- sicily 1424
- sicily 分类
- SIFT算法详解
- iOS:UICollectionView的构建及使用
- Qt中树形结构显示目录结构
- Oracle与MySQL区别
- 如何在main函数前后执行代码
- Sicily 9160. ESEJ
- 机器学习之Logistic回归(c语言实现)
- 使用java.net.URLDecoder获取请求中的中文字符
- POMM-week3
- Longest Substring Without Repeating Characters - LeetCode
- Sicily 10570. VOLIM
- nginx出现504 Gateway Time-out的解决思路
- nanomsg: 协议NN_PAIR, TCP的SERVER端数据结构
- Git学习:利用Git和TortoiseGit把代码传输到网络服务器