Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream f("date.in");
  6. ofstream g("date.out");
  7.  
  8. struct produs{
  9. char producator[501],tip[501];
  10. int anfab,pret,stoc;
  11. }v[1001];
  12.  
  13. int n;
  14.  
  15. bool cmp(const produs &a, const produs &b){
  16. if(strcmp(a.tip , b.tip) != 0){
  17. if(strcmp(a.tip , b.tip) > 0)
  18. return 1;
  19. }else{
  20. return a.pret < b.pret;
  21. }
  22. }
  23.  
  24. void citire(){
  25. int i;
  26. f >> n;
  27. for(i = 1 ; i <= n ; i++)
  28. f >> v[i].producator >> v[i].tip >> v[i].anfab >> v[i].pret >> v[i].stoc;
  29.  
  30. }
  31.  
  32. void afiare_produse(){
  33. int i;
  34. for(i = 1 ; i <= n ; i++)
  35. g << v[i].producator << " " << v[i].tip << " " << v[i].anfab << " " << v[i].pret << " " << v[i].stoc << "\n";
  36.  
  37. }
  38.  
  39. void afiare_dupa_producator(char s[]){
  40. int i;
  41. for(i = 1 ; i <= n ; i++)
  42. if(!strcmp(s , v[i].producator))
  43. g << v[i].producator << " " << v[i].tip << " " << v[i].anfab << " " << v[i].pret << " " << v[i].stoc << "\n";
  44.  
  45. }
  46.  
  47. void sortare(){
  48. sort(v + 1 , v + n + 1 , cmp);
  49. }
  50.  
  51. int main()
  52. {
  53. citire();
  54. sortare();
  55. afiare_produse();
  56.  
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement