Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- string cropToken(string &s){
- if(s.length()==0){
- return "";
- }
- char ch=s[0];
- string res="";
- if((ch=='-')||(ch=='+')||(ch=='*')||(ch=='/')||(ch=='%')||(ch=='(')||(ch==')')||(ch=='!')){
- res+=ch;
- s=s.substr(1);
- return res;
- }
- if((ch<='9')&&(ch>='0')){
- for(int i=0;i<s.length();i++){
- if (!((s[i]<='9')&&(s[i]>='0'))){
- res=s.substr(0,i);
- s=s.substr(i);
- return res;
- }
- }
- res=s;
- s="";
- return res;
- }
- return "$";
- }
- void replaceMinus(string &s){
- string res;
- for(int i=0;i<s.length();i++){
- if(s[i]!=' '){
- res+=s[i];
- }
- }
- if(res[0]=='-'){
- res[0]='!';
- }
- for(int i=0;i<res.length()-1;i++){
- if(res[i]=='('){
- if(res[i+1]=='-'){
- res[i+1]='!';
- }
- }
- }
- s = res;
- }
- int main(int argc, const char * argv[]) {
- // vector <string> vi;
- string vi;
- getline(cin, vi);
- replaceMinus(vi);
- while(vi.length()!=0){
- cout<<cropToken(vi)<<endl;
- }
- }
Add Comment
Please, Sign In to add comment