Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4.  
  5. using namespace std;
  6.  
  7. struct zakaz{
  8. int number;
  9. string FIO;
  10. string tovar;
  11. int cnt;
  12. int sum;
  13. };
  14.  
  15. int main()
  16. {
  17. int n;
  18. cin >> n;
  19. zakaz a[n];
  20. for (int i = 0; i < n; i++){
  21. cin >> a[i].number >> a[i].FIO >> a[i].tovar;
  22. cin >> a[i].cnt >> a[i].sum;
  23. }
  24. // сортировка
  25. for (int i = 0; i < n; i++){
  26. for (int j = 0; j < n - 1; j++){
  27. if (a[j].number > a[j + 1].number){
  28. zakaz temp;
  29. temp = a[j];
  30. a[j] = a[j + 1];
  31. a[j + 1] = temp;
  32. }
  33. }
  34. }
  35. int num;
  36. cin >> num;
  37. int l = 0, r = n - 1;
  38. while (r - l > 1){
  39. int i = (r + l) / 2;
  40. if (a[i].number >= num){
  41. r = i;
  42. }else {
  43. l = i;
  44.  
  45. }
  46. }
  47. if (a[l].number == num){
  48. cout << a[l].number << " " << a[l].FIO;
  49. }else{
  50. cout << a[r].number << " " << a[r].FIO;
  51. }
  52.  
  53.  
  54. return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement