ostapdontstop

evgen

Jun 24th, 2018
135
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cstring>
  3. #include <windows.h>
  4. using namespace std;
  5.  
  6.  
  7. struct fridge{
  8.     char country[20];
  9.     char model[20];
  10.     char quantity[20];
  11. };
  12.  
  13. void print (const fridge &a)
  14. {
  15.     cout<<a.country<<", "<<a.model<<", "<<a.quantity<<endl;
  16. }
  17.  
  18.  
  19. int search (fridge a[], char x[], int size, int beg)
  20. {
  21.    
  22.    
  23.     for (int i=beg; i<size; i++)
  24.     {
  25.         if (strncmp(a[i].model, x, 4)==0) return i;
  26.        
  27.     }
  28.     return size+1;  
  29. }
  30.  
  31. main()
  32. {
  33. SetConsoleCP(1251);
  34. SetConsoleOutputCP(1251);
  35. int size = 4;
  36. fridge a[size] = {{"russian","2018samsung", "40"}, {"german","2016Bosh", "25"}, {"japan","2017sharp", "10"}, {"french","2016LG","3"}};
  37.  
  38. for (int i = 0; i<size;i++) print(a[i]);
  39. char oldest[5];
  40. strncpy(oldest,a[0].model,4);
  41. for (int i = 0; i < size; i++) {
  42.     if(strncmp(oldest,a[i].model,4)>0) strncpy(oldest,a[i].model,4);
  43. }
  44. cout << "search:\n";
  45. for(int y = search(a, oldest,size,0); y<size; y = search(a, oldest,size,y+1)) {
  46.     print (a[y]);
  47. }
  48.  
  49. }
RAW Paste Data