include iostream include stack include string int main std string est

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <stack>
#include <string>
int main() {
std::string p = "(est) + (x+(e^x)) + ((14-dh)*8)";
std::stack<int> position;
for(int i=0; i!=p.length(); i++) {
if(p[i] == '(') {
position.push(i);
}
if(p[i] == ')') {
std::cout<<position.top()<<"-"<<i<<std::endl;
position.pop();
}
}
return 0;
}