de_sousa

Interactor C

Dec 12th, 2025
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include "testlib.h"
  2. #include <bits/stdc++.h>
  3.  
  4. #define LIMIT_CONSTANT 15
  5.  
  6. int n;
  7. std::vector<int> hidden_permutation;
  8.  
  9. void sum_numbers(std::vector<float> numbers) {
  10.  
  11.   float sum = 0;
  12.   for (auto idx : hidden_permutation) {
  13.     sum += numbers[idx - 1];
  14.   }
  15.  
  16.   // std::cout << std::setprecision(std::numeric_limits<float>::max_digits10);
  17.  
  18.   std::cout << sum << std::endl;
  19. }
  20.  
  21. int main(int argc, char **argv) {
  22.  
  23.   registerInteraction(argc, argv);
  24.  
  25.   n = inf.readInt();
  26.   hidden_permutation = inf.readInts(n);
  27.  
  28.   std::cout << n << std::endl;
  29.   int limit = LIMIT_CONSTANT * n;
  30.  
  31.   while (1) {
  32.     std::string token = ouf.readToken();
  33.     if (token == "?") {
  34.  
  35.       if (limit == 0) {
  36.         quitf(_wa, "Exceeded number of queries");
  37.       }
  38.       limit--;
  39.  
  40.       std::vector<float> numbers(n);
  41.       for (auto &x : numbers) {
  42.         x = ouf.readReal();
  43.       }
  44.       sum_numbers(numbers);
  45.  
  46.     } else if (token == "!") {
  47.  
  48.       std::vector<int> guess = ouf.readInts(n);
  49.  
  50.       if (guess == hidden_permutation) {
  51.         quitf(_ok, "Correct guess");
  52.       } else {
  53.         quitf(_wa, "Wrong guess");
  54.       }
  55.  
  56.     } else {
  57.       quitf(_pe, "Expected ? or !, obtained %s", token.c_str());
  58.     }
  59.   }
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment