Guest User

Untitled

a guest
Apr 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. string cropToken(string &s){
  5. if(s.length()==0){
  6. return "";
  7. }
  8. char ch=s[0];
  9. string res="";
  10. if((ch=='-')||(ch=='+')||(ch=='*')||(ch=='/')||(ch=='%')||(ch=='(')||(ch==')')||(ch=='!')){
  11. res+=ch;
  12. s=s.substr(1);
  13. return res;
  14. }
  15. if((ch<='9')&&(ch>='0')){
  16. for(int i=0;i<s.length();i++){
  17.  
  18. if (!((s[i]<='9')&&(s[i]>='0'))){
  19. res=s.substr(0,i);
  20. s=s.substr(i);
  21. return res;
  22. }
  23. }
  24. res=s;
  25. s="";
  26. return res;
  27. }
  28. return "$";
  29. }
  30. void replaceMinus(string &s){
  31. string res;
  32. for(int i=0;i<s.length();i++){
  33. if(s[i]!=' '){
  34. res+=s[i];
  35. }
  36. }
  37.  
  38. if(res[0]=='-'){
  39. res[0]='!';
  40. }
  41. for(int i=0;i<res.length()-1;i++){
  42. if(res[i]=='('){
  43. if(res[i+1]=='-'){
  44. res[i+1]='!';
  45. }
  46. }
  47. }
  48. s = res;
  49. }
  50. int main(int argc, const char * argv[]) {
  51. // vector <string> vi;
  52. string vi;
  53. getline(cin, vi);
  54. replaceMinus(vi);
  55. while(vi.length()!=0){
  56.  
  57. cout<<cropToken(vi)<<endl;
  58. }
  59. }
Add Comment
Please, Sign In to add comment