fork download
  1. #include <bits/stdc++.h>
  2. #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  3. #define ll long long
  4. #define ss string
  5. #define db double
  6. #define endl '\n'
  7. #define pi 3.1415927
  8. #define outd fixed << setprecision(6)
  9. #define all(x) (x).begin(), (x).end()
  10. #define rall(x) (x).rbegin(), (x).rend()
  11. using namespace std;
  12. const int N=510;
  13. int main() {
  14. IOS
  15. vector<int> frq(N);
  16. ss s;
  17. int cnt=0;
  18. while(getline(cin,s)) {
  19. for(int i=0;i<s.size();i++) {
  20. if(s[i]=='{') {
  21. cnt++;
  22. }
  23. else if(s[i]=='}') {
  24. cnt--;
  25. }
  26. else if(s[i]=='p') {
  27. frq[cnt]++;
  28. }
  29. }
  30. }
  31. vector<pair<int,int> > v;
  32. for(int i=1;i<510;i++) {
  33. if(frq[i]!=0) {
  34. v.push_back({i,frq[i]});
  35. }
  36. }
  37. for(int i=0;i<v.size();i++) {
  38. if(i) {
  39. cout<<" + ";
  40. }
  41. if(v[i].second>1) {
  42. cout<<v[i].second;
  43. }
  44. cout<<"N";
  45. if(v[i].first>1) {
  46. cout<<"^" << v[i].first;
  47. }
  48. }
  49. return 0;
  50. }
  51.  
  52.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty