codeforces 190C STL 字符串处理+栈思想
2016-09-07 01:09
387 查看
给一个pair的嵌套声明去掉标点的字符串,然后让你加上标点使得新的字符串符合语法规则
整体递归的思想,注意要将pair < , >作为一个整体
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <cstring>
#include <cstdio>
整体递归的思想,注意要将pair < , >作为一个整体
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <cstring>
#include <cstdio>
using namespace std; int n,cnt=0; string s; stringstream ss; bool type[100001]; pair<int,int> a[100001]; int v[100001]; void print(int x) { if(a[x].first<0) { cout<<"int"; return; } cout<<"pair<"; print(a[x].first); cout<<","; print(a[x].second); cout<<">"; return; } int main() { getline(cin,s); getline(cin,s); ss<<s; for(n=0;!ss.eof();n++) { ss>>s; type =(s=="pair"); } for(int i=n-1;i>=0;i--) { if(type[i]) { if(cnt<2) { cout<<"Error occurred"; return 0; } a[i]=make_pair(v[cnt-1],v[cnt-2]); cnt-=2; } else a[i]=make_pair(-1,-1); v[cnt++]=i; } if(cnt>1) { cout<<"Error occurred"; return 0; } print(0); return 0; }
相关文章推荐
- 2018.2.2【 CodeForces - 501B 】解题报告(STL,map,字符串处理)
- 【CodeForces 155C Hometask】白濑肆×字符串+DP——果然是字符串处理什么的好讨厌啊尤其是换行符的处理看来不用CIN不行了呢DP的转移真心不会啊水到家了怎么办!【1.1%达成】
- [C++]字符串处理方法(STL与C风格)
- Leetcode 13 Roman to Integer 字符串处理+STL
- CodeForces 589A(处理字符串)
- CodeForces 589A -- A. Email Aliases (字符串水题 STL)
- 数据结构作业栈与队列(STL实现)处理字符串之从中部摇摆输出
- STL -- 关于一些字符串处理用到的函数和数据结构
- 【STL】C++使用STL处理替换字符串操作。
- Codeforces 551B ZgukistringZ (字符串处理)
- CodeForces 23A You're Given a String...(字符串处理)
- codeforces 195C Try and Catch 字符串处理
- CodeForces 159D 字符串处理
- CodeForces 4C Registration system(字符串处理 | map)
- STL 字符串处理
- 字符串处理(STL之string)
- 用栈的思想处理字符串倒置问题更清晰
- STL 字符串处理
- 使用STL中的vector容器类处理字符串
- codeforces 200D Programming Language 字符串处理