Codeforces Round #387 (Div. 2) E. Comments sstream的用法

E. Comments

链接:

http://codeforces.com/contest/747/problem/E

代码:

 1 #include <map>
 2 #include <set>
 3 #include <cmath>
 4 #include <queue>
 5 #include <stack>
 6 #include <cstdio>
 7 #include <string>
 8 #include <vector>
 9 #include <cstring>
10 #include <sstream>
11 #include <iostream>
12 #include <algorithm>
13 #include <functional>
14 using namespace std;
15 #define rep(i,a,n) for (int i=a;i<=n;i++)
16 #define per(i,a,n) for (int i=n;i>=a;i--)
17 #define pb push_back
18 #define mp make_pair
19 #define all(x) (x).begin(),(x).end()
20 #define fi first
21 #define se second
22 #define SZ(x) ((int)(x).size())
23 typedef vector<int> VI;
24 typedef long long ll;
25 typedef pair<int, int> PII;
26 const ll mod = 1e9 + 7;
27 const int inf = 0x3f3f3f3f;
28 const double eps = 1e-7;
29 // head
30 
31 const int MAXN = 1000005;
32 vector<pair<string, int> >v;
33 vector<string>res[MAXN];
34 
35 int main()
36 {
37     ios::sync_with_stdio(false);
38     cin.tie(NULL);
39     string str;
40     cin >> str;
41     for (int i = 0; i<(int)str.size(); i++)
42         if (str[i] == ',')str[i] = ' ';
43     stringstream ss;
44     ss.str(str);
45     while (ss >> str)
46     {
47         int tmp;
48         ss >> tmp;
49         v.push_back(make_pair(str, tmp));
50     }
51     stack<int>st;
52     st.push(-1);
53     for (int i = 0, j = 1; i<(int)v.size(); i++)
54     {
55         while (st.top() == 0)j--, st.pop();
56         res[j].push_back(v[i].first);
57         st.top()--;
58         st.push(v[i].second), j++;
59     }
60     int mx = 0;
61     for (int i = 1; i<MAXN && !res[i].empty(); i++)
62         mx = i;
63     cout << mx << endl;
64     for (int i = 1; i <= mx; i++)
65     {
66         for (int j = 0; j<(int)res[i].size(); j++)
67             cout << res[i][j] << " ";
68         cout << endl;
69     }
70     return 0;
71 }

 

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值