0
#include <iostream>
#include <vector>
#include <math.h>
using std::cout;
using std::cin;
using std::endl;
using std::vector;
int main()
{

    int64_t default_min = 1'000'000'000;
    int64_t n;
    cin >> n;
    vector<int64_t> city(n);
    vector<int64_t> min(n, default_min);
    vector<int64_t> max(n, 0);

    for (auto& i : city) 
    {
        cin >> i;
    }
    for (int i = 0; i < n; i++) {//max
        if (i != 0 || i != n - 1) {
            if (signed int(city[i] - city[i-1]) >= signed int(city[i+1] - city[i]))
            {
                max[i] = abs(city[i] - city[i - 1]);
                min[i] = abs(city[i] - city[i + 1]);
            }
            else {
                min[i] = abs(city[i] - city[i - 1]);
                max[i] = abs(city[i] - city[i + 1]);
            }
        }
        else if (i == 0) {
            min[i] = city[1] - city[0];
            max[i] = city[n-1] - city[0];
        }
        else if (i == n-1) {
            min[i] = city[n-1] - city[n-2];
            max[i] = max[0];
        }
    }
    for (int i=0;i<n;i++)
    {
        cout << min[i] << " " << max[i]<<endl;
    }
    
}

i tried in the comparison line to cast it as unsigned or signed on both sides but it didn't work ,i reached this point because so far i couldn't find other way to compare values inside vectors easily.. so is there way to avoid the mismatch /match error by either casting or comparing vectors in more efficient way

Ze BOy
  • 1
  • 1
  • 2
    What's the exact error message? – Brian61354270 Apr 11 '22 at 12:05
  • Looks like you have a syntax error around the casts. Either wrap the types names in parentheses, or better yet just drop them entirely since the cast appears to be superfluous. – Brian61354270 Apr 11 '22 at 12:08
  • An invalid parameter was passed to a function that considers invalid parameters fatal. – Ze BOy Apr 11 '22 at 12:09
  • 2
    You can't use multi-word typenames (like `signed int`) in a function-style cast. Just replace the `signed int(...)` stuff with `signed(...)` - the effect is the same. Related: https://stackoverflow.com/a/52920327/10871073 – Adrian Mole Apr 11 '22 at 12:09
  • the error still occurs after replacement – Ze BOy Apr 11 '22 at 12:11
  • The condition `if (i != 0 || i != n - 1)` is almost always true. Did you mean to use `&&` here? I would have sorted out the other two specific cases first, and put this in an `else` part. – BoP Apr 11 '22 at 12:27
  • 1
    Have you tried using `static_cast(...)` instead? Also, I agree with @Brian: the casts seem to be superfluous in the first place. – FMeinicke Apr 11 '22 at 12:31
  • @FMeinicke using static cast worked but what is meant by the cast is superfluous so i can avoid it later? – Ze BOy Apr 11 '22 at 15:34
  • Well, you're comparing two `int64_t`'s so you don't need to cast them to any other type - they're already the same type. A cast is only needed if you're comparing integers of different signedness, for example (e.g. a `int64_t` and a `uint64_t`; here the compiler would do an implicit cast but it's generally better to explicitly do the casting yourself). GCC, for example, warns you about comparisons of types with different signedness when you add the `-Wextra` compile flag: See https://godbolt.org/z/zbYsv7T8c for an example. The code compiles but the implicit cast might not do what you expect – FMeinicke Apr 12 '22 at 16:42

0 Answers0