Advertisement
Glenpl

Untitled

Dec 3rd, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4. using namespace std;
  5. int main()
  6. {
  7. int a=0,c[101];
  8. string b[101];
  9.  
  10. while(getline(cin,b[a]))
  11. a++;
  12.  
  13. for (int i =0; i<=a;i++)
  14. {
  15.    if(b[i].find("+")!=string::npos)
  16. {
  17. b[i].erase(0,2);
  18.  int ch_place = b[i]. find(" ") ;
  19.  
  20.  
  21. string leftside_str = "" ;
  22. string rigthside_str = "";
  23. int leftside ;
  24. int rigthside ;
  25.  
  26.  for ( int j = 0 ; j < ch_place ; j++ )
  27.  
  28. leftside_str +=b [i ][j] ;
  29.  
  30.  for ( int j= ++ ch_place ; j <b[i].length() ; j++ )
  31.  
  32. rigthside_str + = b[i] [j] ;
  33.  
  34. leftside = atoi(leftside_str. c_str ()) ;
  35. rigthside = atoi(rigthside_str. c_str ()) ;
  36. c[i] = leftside + rigthside;
  37.  
  38. }
  39.   if(b[i].find("-") !=string::npos)
  40. {
  41.  b[i].erase(0,2);
  42.  int ch_place = b[i]. find(" ") ;
  43.  
  44.  
  45. string leftside_str = "" ;
  46. string rigthside_str = "";
  47. int leftside ;
  48. int rigthside ;
  49.  
  50.  for ( int j = 0 ; j < ch_place ; j++ )
  51.  
  52. leftside_str +=b [i ][j] ;
  53.  
  54.  for ( int j= ++ ch_place ; j <b[i].length() ; j++ )
  55.  
  56. rigthside_str + = b[i] [j] ;
  57.  
  58. leftside = atoi(leftside_str. c_str ()) ;
  59. rigthside = atoi(rigthside_str. c_str ()) ;
  60. c[i] = leftside - rigthside;
  61. }
  62.   if(b[i].find("*") !=string::npos)
  63. {
  64.  b[i].erase(0,2);
  65.  int ch_place = b[i]. find(" ") ;
  66.  
  67.  
  68. string leftside_str = "" ;
  69. string rigthside_str = "";
  70. int leftside ;
  71. int rigthside ;
  72.  
  73.  for ( int j = 0 ; j < ch_place ; j++ )
  74.  
  75. leftside_str +=b [i ][j] ;
  76.  
  77.  for ( int j= ++ ch_place ; j <b[i].length() ; j++ )
  78.  
  79. rigthside_str + = b[i] [j] ;
  80.  
  81. leftside = atoi(leftside_str. c_str ()) ;
  82. rigthside = atoi(rigthside_str. c_str ()) ;
  83. c[i] = leftside * rigthside;
  84. }
  85.   if(b[i].find("/") !=string::npos)
  86. {
  87.  b[i].erase(0,2);
  88.  int ch_place = b[i]. find(" ") ;
  89.  
  90.  
  91. string leftside_str = "" ;
  92. string rigthside_str = "";
  93. int leftside ;
  94. int rigthside ;
  95.  
  96.  for ( int j = 0 ; j < ch_place ; j++ )
  97.  
  98. leftside_str +=b [i ][j] ;
  99.  
  100.  for ( int j= ++ ch_place ; j <b[i].length() ; j++ )
  101.  
  102. rigthside_str + = b[i] [j] ;
  103.  
  104. leftside = atoi(leftside_str. c_str ()) ;
  105. rigthside = atoi(rigthside_str. c_str ()) ;
  106. c[i] = leftside / rigthside;
  107. }
  108.   if(b[i].find("%") !=string::npos)
  109. {
  110.  b[i].erase(0,2);
  111.  int ch_place = b[i]. find(" ") ;
  112.  
  113.  
  114. string leftside_str = "" ;
  115. string rigthside_str = "";
  116. int leftside ;
  117. int rigthside ;
  118.  
  119.  for ( int j = 0 ; j < ch_place ; j++ )
  120.  
  121. leftside_str +=b [i ][j] ;
  122.  
  123.  for ( int j= ++ ch_place ; j <b[i].length() ; j++ )
  124.  
  125. rigthside_str + = b[i] [j] ;
  126.  
  127. leftside = atoi(leftside_str. c_str ()) ;
  128. rigthside = atoi(rigthside_str. c_str ()) ;
  129. c[i] = leftside % rigthside;
  130. }
  131. }
  132.  
  133. for(int i=0; i<=a;i++)
  134. cout<<c[i]<<"\n";
  135.  
  136. return 0;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement