Advertisement
kxcoze

satie++

Apr 21st, 2020
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.43 KB | None | 0 0
  1. #include <iostream>                                                        
  2. #include <string>                                            
  3.      
  4. using namespace std;                                            
  5.      
  6. void inputStr(string &x, int t, char sym) {                                  
  7.     x += '(';                                                                
  8.     for (int i = 0; i < t; i++)                                          
  9.         x += sym;                                                          
  10.     x += ')';                                                                
  11. }                                                                          
  12.                                                                              
  13. int main() {                                                
  14.     setlocale(LC_ALL, "Rus");                                                
  15.     string str;                                                        
  16.     cout << "Введите строку: \n";                                            
  17.     cin >> str;                                                            
  18.                                                                            
  19.     int m;                                                              
  20.     string ans;                                                              
  21.     for (int i = 0; i < str.size(); i++) {                                    
  22.         if (isdigit(str[i])) {                                                
  23.             m = str[i] - '0';                                                
  24.             if (m % 2 == 0) {                                                
  25.                 if (!m) m++;                                                  
  26.                 inputStr(ans, m, '+');                                        
  27.             } else                                                            
  28.                 inputStr(ans, m, '-');                                        
  29.         } else                                                      
  30.             ans += str[i];                                  
  31.     }                                                                        
  32.                                                                              
  33.     cout << ans << '\n';                                                      
  34.     return 0;                                                                
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement