fork download
  1. #include <bits/stdc++.h>
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. int N;
  10. cin >> N;
  11.  
  12. string S;
  13. cin >> S;
  14. vector<int> SUP(N + 1), INF(N + 1);
  15.  
  16. int h = 0;
  17. int k = 0;
  18. bool possibile = true;
  19.  
  20. for (int i = 0; i < N; i++) {
  21. if (S[i] == '+') {
  22. SUP[h] = i;
  23. h = h + 1;
  24. } else if (S[i] == '-') {
  25. INF[k] = i;
  26. k = k + 1;
  27. }
  28. }
  29.  
  30. if (h == 0 || k == 0) possibile = false;
  31. if (S[0] != '+' || S[N - 1] != '-') possibile = false;
  32.  
  33. if (possibile) {
  34. cout << "YES" << endl;
  35. for (int i = 0; i <= h - 1; i++) cout << SUP[i] << ' ';
  36. for (int i = k - 1; i >= 0; i--) cout << INF[i] << ' ';
  37. std::cout << '\n';
  38. } else {
  39. cout << "NO" << endl;
  40. }
  41.  
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0s 544KB
stdin
8
+-+-+-+-
stdout
YES
0 2 4 6 7 5 3 1