hihoCoder - 1103 - Colorful Lecture Note(栈、字符串处理)
来源:互联网 发布:逆袭网络剧第二季 编辑:程序博客网 时间:2024/06/08 19:55
#1103 : Colorful Lecture Note
时间限制:10000ms 单点时限:1000ms 内存限制:256MB
描述
Little Hi is writing an algorithm lecture note for Little Ho. To make the note more comprehensible, Little Hi tries to color some of the text. Unfortunately Little Hi is using a plain(black and white) text editor. So he decides to tag the text which should be colored for now and color them later when he has a more powerful software such as Microsoft Word.
There are only lowercase letters and spaces in the lecture text. To mark the color of a piece of text, Little Hi add a pair of tags surrounding the text, at the beginning and at the end where COLOR is one of “red”, “yellow” or “blue”.
Two tag pairs may be overlapped only if one pair is completely inside the other pair. Text is colored by the nearest surrounding tag. For example, Little Hi would not write something like “aaabbbccc”. However “aaabbbccc” is possible and “bbb” is colored blue.
Given such a text, you need to calculate how many letters(spaces are not counted) are colored red, yellow and blue.
输入
Input contains one line: the text with color tags. The length is no more than 1000 characters.
输出
Output three numbers count_red, count_yellow, count_blue, indicating the numbers of characters colored by red, yellow and blue.
样例输入
< yellow>aaa< blue>bbb< /blue>ccc< /yellow>dddd< red>abc< /red>
样例输出
3 6 3
题意:给你一串字符串< > < />,每个括号之内颜色字体的统计,按顺序输出红色、黄色、蓝色字体的个数
这道题猛一看有种括号配对的感觉,其实也差不多,把在栈中压入标记来统计
#include<cstdio>#include<cstring>#include<cctype>#include<algorithm>#include<stack>using namespace std;stack<char>s;int main(){ char a[1010]; while(gets(a)){ int r, y, b; int len = strlen(a); r = y = b = 0; for(int i = 0; i < len; i++){ if(a[i] == '<'){ if(a[i+1] == 'r'){ s.push('r'); i+=4; continue; } else if(a[i+1] == 'y'){ s.push('y'); i+=7; continue; } else if(a[i+1] == 'b'){ s.push('b'); i+=5; continue; } else if(a[i+1] == '/'){ s.pop(); if(a[i+2]=='r'){ i+=5; continue; } else if(a[i+2]=='y'){ i+=8; continue; } else if(a[i+2]=='b'){ i+=6; continue; } } } else{ if(!s.empty()){ if(s.top()=='r' && isalpha(a[i])) r++; else if(s.top()=='y' && isalpha(a[i])) y++; else if(s.top()=='b' && isalpha(a[i])) b++; } } } printf("%d %d %d\n", r, y, b); } return 0;}
- hihoCoder - 1103 - Colorful Lecture Note(栈、字符串处理)
- hihocoder 1103 Colorful Lecture Note(字符串处理)
- hihoCoder - 1103 - Colorful Lecture Note (栈~~)
- hihoCoder: Colorful Lecture Note
- hihoCoder 1103 Colorful Lecture Note 微软苏州校招笔试 1月10日
- Colorful Lecture Note(栈的模拟)
- 微软笔试题《Colorful Lecture Note》
- 微软苏州校招笔试题目(1月10日)Colorful Lecture Note的解法
- hihoCoder 1039 字符消除(字符串处理)
- hihoCoder 字符消除 (字符串处理)(枚举)
- hihocoder 1039 字符串处理
- Note-02-字符串处理
- CS107-Lecture 3-Note
- CS107-Lecture 4-Note
- CS107-Lecture 5-Note
- CS107-Lecture 6-Note
- CS107-Lecture 7-Note
- hihoCoder #1052 : 基因工程 ( 字符串处理 )
- 关键字 static和final
- Activity的4种加载模式解析:
- opencv开发之MFC的.SetWindowTextA() + OnTimer(UINT_PTR nIDEvent) +cvNamedWindow 在MFC上显示
- 整数划分问题之 划分数
- 杭电(hdu) 2049 不容易系列之(4)——考新郎
- hihoCoder - 1103 - Colorful Lecture Note(栈、字符串处理)
- 使用Snappy 压缩方式报错“java.lang.UnsatisfiedLinkError: no snappyjava in java.library.path”
- 编写socket通信服务器端程序时的错误解决方法
- 来自大数据的反思:需要你读懂的10个小故事
- 【笔试】4、正整数分解质因数
- 【机房收费系统】——报表制作
- UIViewController
- UIViewController的生命周期
- Code Forces 37A Towers