Untitled
user_7227489
plain_text
a month ago
1.3 kB
3
Indexable
Never
#include <iostream> #include <vector> #include <algorithm> using namespace std; static void sink(int row,int col,int size){ int lefterCol = max(col-5,1); string s1; for (int i = lefterCol; i < lefterCol + 10 && i <=size; ++i) { cout << i << ' ' << col << endl; cin >> s1; } int upperRow = max(row-5,1); for (int i = upperRow; i < upperRow + 10 && i <=size; ++i) { cout << row << ' ' << i << endl; cin >> s1; } } 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