zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    使用 RMAN 同步数据库
    关于MongoDB分布式高可用集群实现
    Oracle排错总结
    Oracle中Restore和Recovery的区别
    linux下防火墙iptables原理及使用
    RHEL6.5上升级OpenSSH7.4p1
    awk中next以及getline用法示例
    Linux下Redis的安装和部署
    Mongodb集群搭建的三种方式
    天地图服务地址
  • 原文地址:https://www.cnblogs.com/baocong/p/6490761.html
Copyright © 2011-2022 走看看