Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. ifstream fin("reteta.in");
  8. ofstream fout("reteta.out");
  9.  
  10. struct produs
  11. {
  12. char tip[21];
  13. int cantitate_totala_produs;
  14. }P[101];
  15.  
  16. char s[1001],*p,aux[21],separatori[]="() ";
  17.  
  18. int main()
  19. {
  20. bool ok;
  21. int timp_de_preparare_produs=0,timp_de_preparare_total=0;
  22.  
  23. fin.get(s,1001);
  24.  
  25. for(int i=0; i<strlen(s); ++i)
  26. {
  27. if(s[i]==')')ok=1;
  28. if(ok==1 && isdigit(s[i])!=0)
  29. {
  30. timp_de_preparare_produs=0;
  31. while(isdigit(s[i])!=0)
  32. {
  33. timp_de_preparare_produs=timp_de_preparare_produs*10+(s[i]-'0');
  34.  
  35. if(isdigit(s[i])){
  36. strcpy(aux,s+i+1);
  37.  
  38. strcpy(s+i,aux);}
  39. }
  40. ok=0;
  41. fout<<timp_de_preparare_produs<<endl;
  42. timp_de_preparare_total=timp_de_preparare_produs+timp_de_preparare_total;
  43. }
  44. }
  45. fout<<timp_de_preparare_total<<"\n";
  46.  
  47. int t=0,cantitate_produs;
  48.  
  49. p=strtok(s,separatori);
  50. while(p!=0)
  51. {
  52. /* cantitate_produs=0;
  53. ok=0;
  54. for(int i=0; i<=t; ++i)
  55. {
  56. if(strcmp(p,P[i].tip)==0)
  57. {
  58. p=strtok(NULL,separatori);
  59. for(int j=0; j<strlen(p); ++j)
  60. cantitate_produs=cantitate_produs*10+int(p[j]-'0');
  61. P[i].cantitate_totala_produs=P[i].cantitate_totala_produs+cantitate_produs;
  62. ok=1;
  63. break;
  64. }
  65. }
  66. if(ok==0)
  67. {
  68. ++t;
  69. strcpy(P[t].tip,p);
  70. p=strtok(NULL,separatori);
  71. for(int j=0; j<strlen(p); ++j)
  72. cantitate_produs=cantitate_produs*10+int(p[j]-'0');
  73. P[t].cantitate_totala_produs=P[t].cantitate_totala_produs+cantitate_produs;
  74. }
  75. p=strtok(NULL,separatori);*/
  76. fout<<p<<endl;
  77. p=strtok(NULL,separatori);
  78. }
  79. for(int i=1; i<=t; ++i)
  80. fout<<P[i].tip<<" "<<P[i].cantitate_totala_produs<<"\n";
  81.  
  82.  
  83.  
  84.  
  85. return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement