fork(4) download
  1. // Name:- Kunal Sheth
  2.  
  3. // Problem:- Simple Arithmetics II
  4.  
  5. // Link:- http://w...content-available-to-author-only...j.com/problems/ARITH2/
  6.  
  7. // Site:- SPOJ
  8.  
  9.  
  10.  
  11. //header files
  12.  
  13. #include<iostream>
  14. #include<cstdio>
  15. #include<algorithm>
  16. #include<vector>
  17. #include<map>
  18. #include<cmath>
  19. #include<cstring>
  20. using namespace std;
  21.  
  22. //end of header files
  23.  
  24.  
  25. //definitions
  26.  
  27. #define MOD 1000000007
  28. #define llu long long unsigned
  29. #define lld long long
  30. #define ld long
  31.  
  32. //end of definitions
  33.  
  34.  
  35. //fast input
  36.  
  37. int scan_d() {int ip=getchar_unlocked(),ret=0,flag=1;for(;ip<'0'||ip>'9';ip=getchar_unlocked())if(ip=='-'){flag=-1;ip=getchar_unlocked();break;}for(;ip>='0'&&ip<='9';ip=getchar_unlocked())ret=ret*10+ip-'0';return flag*ret;}
  38. ld scan_ld() {int ip=getchar_unlocked(),flag=1;ld ret=0;for(;ip<'0'||ip>'9';ip=getchar_unlocked())if(ip=='-'){flag=-1;ip=getchar_unlocked();break;}for(;ip>='0'&&ip<='9';ip=getchar_unlocked())ret=ret*10+ip-'0';return flag*ret;}
  39. inline lld scan_lld() {int ip=getchar_unlocked(),flag=1;lld ret=0;for(;ip<'0'||ip>'9';ip=getchar_unlocked())if(ip=='-'){flag=-1;ip=getchar_unlocked();break;}for(;ip>='0'&&ip<='9';ip=getchar_unlocked())ret=ret*10+ip-'0';return flag*ret;}
  40. llu scan_llu() {int ip=getchar_unlocked();llu ret=0;for(;ip<'0'||ip>'9';ip=getchar_unlocked());for(;ip>='0'&&ip<='9';ip=getchar_unlocked())ret=ret*10+ip-'0';return ret;}
  41.  
  42. //end of fast input
  43.  
  44. //fast output
  45.  
  46. //no line break
  47. void print_d(int n) {if(n<0){n=-n;putchar_unlocked('-');}int i=10;char output_buffer[10];do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<10);}
  48. void print_ld(ld n) {if(n<0){n=-n;putchar_unlocked('-');}int i=11;char output_buffer[11];do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<11);}
  49. void print_lld(lld n) {if(n<0){n=-n;putchar_unlocked('-');}int i=21;char output_buffer[21];do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<21);}
  50. void print_llu(llu n) {int i=21;char output_buffer[21];do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<21);}
  51.  
  52. //new line
  53. void println_d(int n) {if(n<0){n=-n;putchar_unlocked('-');}int i=10;char output_buffer[11];output_buffer[10]='\n';do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<11);}
  54. void println_ld(ld n) {if(n<0){n=-n;putchar_unlocked('-');}int i=11;char output_buffer[12];output_buffer[11]='\n';do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<12);}
  55. void println_lld(lld n) {if(n<0){n=-n;putchar_unlocked('-');}int i=21;char output_buffer[22];output_buffer[21]='\n';do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<22);}
  56. void println_llu(llu n) {int i=21;char output_buffer[22];output_buffer[21]='\n';do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<22);}
  57.  
  58. //special char
  59. char sp;
  60. void printsp_d(int n) {if(n<0){n=-n;putchar_unlocked('-');}int i=10;char output_buffer[11];output_buffer[10]=sp;do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<11);}
  61. void printsp_ld(ld n) {if(n<0){n=-n;putchar_unlocked('-');}int i=11;char output_buffer[12];output_buffer[11]=sp;do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<12);}
  62. void printsp_lld(lld n) {if(n<0){n=-n;putchar_unlocked('-');}int i=21;char output_buffer[22];output_buffer[21]=sp;do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<22);}
  63. void printsp_llu(llu n) {int i=21;char output_buffer[22];output_buffer[21]=sp;do{output_buffer[--i]=(n%10)+'0';n/=10;}while(n);do{putchar_unlocked(output_buffer[i]);}while(++i<22);}
  64.  
  65. //end of fast output
  66.  
  67.  
  68. //extra functions
  69.  
  70. //end of extra fnctions
  71.  
  72.  
  73. //main
  74.  
  75. int main()
  76. {
  77. int t=scan_d();
  78. while(t--)
  79. {
  80. long long int n=scan_lld();
  81. bool is=1;
  82. while(is)
  83. {
  84. char op;
  85. op=getchar_unlocked();
  86. while(op!='+'&&op!='-'&&op!='/'&&op!='*'&&op!='=')
  87. op=getchar_unlocked();
  88. switch(op)
  89. {
  90. case '+':
  91. {
  92. n+=scan_lld();
  93. break;
  94. }
  95. case '-':
  96. {
  97. n-=scan_lld();
  98. break;
  99. }
  100. case '*':
  101. {
  102. n*=scan_lld();
  103. break;
  104. }
  105. case '/':
  106. {
  107. n/=scan_lld();
  108. break;
  109. }
  110. case '=':
  111. {
  112. is=0;
  113. break;
  114. }
  115. }
  116. }
  117. println_lld(n);
  118. }
  119. return 0;
  120. }
  121.  
  122. //end of main
Success #stdin #stdout 0s 3308KB
stdin
4

1 + 1 * 2 =

29 / 5 =

103 * 103 * 5 =

50 * 40 * 250 + 791 =
stdout
4
5
53045
500791