Ilya_konstantinov

Untitled

Mar 20th, 2026
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. struct Node {
  2. Node * next;
  3. int data;
  4. };
  5.  
  6.  
  7. #include "solution.h"
  8.  
  9. #include <cassert>
  10. #include <climits>
  11. #include <cstdlib>
  12. #include <iostream>
  13.  
  14. #define N 10050060
  15.  
  16. int main() {
  17. assert(sizeof(Node) <= 16);
  18.  
  19. LinkedList odd(N);
  20. LinkedList even(N);
  21.  
  22. srand(42);
  23.  
  24. for (int i = 0; i != N; ++i) {
  25. int x = rand();
  26. if (x % 2 == 0) {
  27. even.push_front(x);
  28. } else {
  29. odd.push_front(x);
  30. }
  31. }
  32.  
  33. long long sum = 0;
  34. long long min = LONG_MAX;
  35. long long max = 0;
  36.  
  37. {
  38. const Node *node = odd.head();
  39. while (node) {
  40. sum += node->data;
  41. node = node->next;
  42. }
  43. }
  44. {
  45. const Node *node = odd.head();
  46. while (node) {
  47. if (node->data < min) {
  48. min = node->data;
  49. }
  50. node = node->next;
  51. }
  52. }
  53. {
  54. const Node *node = odd.head();
  55. while (node) {
  56. if (node->data > max) {
  57. max = node->data;
  58. }
  59. node = node->next;
  60. }
  61. }
  62. std::cout << sum << ' ' << min << ' ' << max << std::endl;
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment