Untitled
user_7227489
plain_text
a month ago
1.5 kB
2
Indexable
Never
#include <iostream> #include <vector> #include <algorithm> using namespace std; static void sink(int row,int col,int size){ int lefterCol = max(col-4,1); string s1; for (int col2 = lefterCol; col2 < lefterCol + 10 && col2 <= size; ++col2) { cout << row << ' ' << col2 << endl; cin >> s1; if(s1=="sunk") return; } int upperRow = max(row-4,1); for (int row2 = upperRow; row2 < upperRow + 10 && row2 <= size; ++row2) { cout << row2 << ' ' << col << endl; cin >> s1; if(s1=="sunk") return; } } int main() { int size,ships,index; cin >> size >> ships; vector<vector<int>> hits; string s1; for (index = 5; index <= size; index+=5) { int row = index,col=1; while(row > 0){ cout << row << ' ' << col << endl; cin >> s1; if(s1=="hit") hits.push_back({row, col}); row--; col++; } } for (index = 5-size%5+1; index <= size; index+=5) { int row = index,col= size; while(row <= size){ cout << row << ' ' << col << endl; cin >> s1; if(s1=="hit") hits.push_back({row,col}); row++; col--; } } for (int i = 0; i < ships; ++i) { sink(hits[i][0],hits[i][1],size); } return 0; }
Leave a Comment