fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. typedef void exec(long long &value);
  7. int read() { int x; cin>>x; return x; }
  8. void nic(long long &value) {}
  9. void dodaj(long long &value) { value+=read(); }
  10. void odejmij(long long &value) { value-=read(); }
  11. bool doit(long long &value)
  12. {
  13. static struct { const char *txt; exec *doit; } Tb[]={{"nic",&nic},{"dodaj",&dodaj},{"odejmij",&odejmij}};
  14. static char buf[256];
  15. cin>>setw(255)>>buf;
  16. for(unsigned i=0;i<sizeof(Tb)/sizeof(*Tb);++i) if(!strcmp(buf,Tb[i].txt)) Tb[i].doit(value);
  17. return cin;
  18. }
  19.  
  20. int main()
  21. {
  22. long long value=0;
  23. while(doit(value)) cout<<value<<endl;
  24. return 0;
  25. }
Success #stdin #stdout 0s 3300KB
stdin
dodaj 7
nic
odejmij 4
dodaj 3
nic
dodaj 2
stdout
7
7
3
6
6
8