Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <windows.h>
- using namespace std;
- struct holod{
- char country[80], model[80];
- int stock;
- };
- void print (const holod &a)
- {
- cout << a.country<<" "<< a.model <<" "<< a.stock <<endl;
- }
- int search (holod *a, int n, const char *old, int position)
- {
- for (int i=position; i<n; i++) if (strncmp(a[i].model, old, 4)==0) return i;
- return n;
- }
- main()
- {
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- int n = 4;
- holod a[n] = {
- {"russian","2018samsung", 2},
- {"german","2016Bosh", 2},
- {"japan","2017sharp", 2},
- {"french","2016LG",2}
- };
- for (int i = 0; i<n ; i++)
- print(a[i]);
- char old[5];
- strncpy(old,a[0].model,4);
- for (int i = 0; i < n; i++) {
- if(strncmp(old,a[i].model,4)>0) strncpy(old,a[i].model,4);
- }
- cout << "search:\n";
- int s = search(a, n, old,0);
- while (s!=n) {
- print (a[s]);
- s = search(a, n, old,s+1);
- }
- }
Add Comment
Please, Sign In to add comment