Submission #1068739

#TimeUsernameProblemLanguageResultExecution timeMemory
1068739vjudge1Naval battle (CEOI24_battle)C++17
Compilation error
0 ms0 KiB
// Online C++ compiler to run C++ program online #include <bits/stdc++.h> using namespace std; #define int long long #define ff first #define ss second struct ship{ int x,y; char dir; /* Northern — decreases the y coordinate by 1 Southern — increases the y coordinate by 1 Eastern — increases the x coordinate by 1 Western — decreases the x coordinate by 1 */ }; int calc(ship a, ship b) { if (a.dir == b.dir) return 0; if (a.x == b.x) { if (a.y < b.y) swap(a,b); if (a.dir == 'N' && b.dir == 'S') return (a.y-b.y)/2; return 0; } if (a.y == b.y) { if (a.x < b.x) swap(a,b); if (a.dir == 'W' && b.dir == 'E') return (a.x-b.x)/2; return 0; } if (a.x + a.y == b.x + b.y) { if(a.dir == 'N') { if (b.dir == 'E') { if (b.x < a.x && a.y > b.y) return abs(a.x-b.x); } else if (b.dir == 'W') { if (b.x > a.x && a.y > b.y) return abs(a.x-b.x); } } else if (a.dir == 'S') { if (b.dir == 'E') { if (b.x < a.x && a.y < b.y) return abs(a.x-b.x); } else if (b.dir == 'W') { if (b.x > a.x && a.y < b.y) return abs(a.x-b.x); } } else if (a.dir == 'W') { if (b.dir == 'N') { if (b.x < a.x && a.y < b.y) return abs(a.x-b.x); } else if (b.dir == 'S') { if (b.x < a.x && a.y > b.y) return abs(a.x-b.x); } } else if (a.dir == 'E') { if (b.dir == 'N') { if (b.x > a.x && a.y < b.y) return abs(a.x-b.x); } else if (b.dir == 'S') { if (b.x > a.x && a.y > b.y) return abs(a.x-b.x); } } } return 0; } signed main() { ios::sync_with_stdio(0); int n; cin >> n; vector<ship> v(n); for (int i = 0; i < n; i++) { cin >> v[i].x >> v[i].y >> v[i].dir; } if (n>2) { cout << "n\n"; return; } int a = v[0]; int b = v[1]; if (calc(a,b)) { cout << "1\n2\n"; } return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:111:9: error: return-statement with no value, in function returning 'int' [-fpermissive]
  111 |         return;
      |         ^~~~~~
Main.cpp:113:16: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<ship>, ship>::value_type' {aka 'ship'} to 'long long int' in initialization
  113 |     int a = v[0];
      |                ^
Main.cpp:114:16: error: cannot convert '__gnu_cxx::__alloc_traits<std::allocator<ship>, ship>::value_type' {aka 'ship'} to 'long long int' in initialization
  114 |     int b = v[1];
      |                ^
Main.cpp:115:14: error: could not convert 'a' from 'long long int' to 'ship'
  115 |     if (calc(a,b))
      |              ^
      |              |
      |              long long int