結果

問題 No.455 冬の大三角
ユーザー startcpp
提出日時 2016-12-07 10:54:45
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 789 bytes
コンパイル時間 415 ms
コンパイル使用メモリ 55,000 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-29 21:17:30
合計ジャッジ時間 2,332 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 54
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:16:17: warning: ‘gx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   16 |         int gy, gx;
      |                 ^~
main.cpp:16:13: warning: ‘gy’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   16 |         int gy, gx;
      |             ^~
main.cpp:15:17: warning: ‘sx’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   15 |         int sy, sx;
      |                 ^~
main.cpp:15:13: warning: ‘sy’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   15 |         int sy, sx;
      |             ^~

ソースコード

diff #

//素直に実装。場合分けでも解けるけど、素朴に実装したほうが速かった。
#include <iostream>
#include <string>
using namespace std;

int h, w;
string s[100];

int main() {
	int i, j;
	
	cin >> h >> w;
	for (i = 0; i < h; i++) cin >> s[i];
	
	int sy, sx;
	int gy, gx;
	int state = 0;
	
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			if (s[i][j] == '*') {
				if (!state) {
					sy = i;
					sx = j;
					state++;
				}
				else {
					gy = i;
					gx = j;
				}
			}
		}
	}
	
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			if (s[i][j] == '*') continue;
			if ((sy - i) * (gx - j) == (gy - i) * (sx - j)) continue;
			s[i][j] = '*';
			break;
		}
		if (j < w) break;
	}
	
	for (i = 0; i < h; i++) {
		cout << s[i] << endl;
	}
	
	return 0;
}
0