結果

問題 No.1362 [Zelkova 8th Tune] Black Sheep
ユーザー mmn15277198
提出日時 2021-01-24 10:55:07
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 13 ms / 1,000 ms
コード長 418 bytes
コンパイル時間 949 ms
コンパイル使用メモリ 72,896 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-01-02 14:19:20
合計ジャッジ時間 3,059 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:22:17: warning: ‘ans1’ may be used uninitialized [-Wmaybe-uninitialized]
   22 |                 if(s[i] == ans1)ans2 = i + 1;
      |                 ^~
main.cpp:12:14: note: ‘ans1’ was declared here
   12 |         char ans1;
      |              ^~~~
main.cpp:24:32: warning: ‘ans2’ may be used uninitialized [-Wmaybe-uninitialized]
   24 |         cout << ans2 << " " << ans1 << endl;
      |                                ^~~~
main.cpp:20:13: note: ‘ans2’ was declared here
   20 |         int ans2;
      |             ^~~~

ソースコード

diff #

#include <iostream>
#include <map>
using namespace std;
int main(){
	string s;
	cin >> s;
	map<char , int> cnt;
	int n = s.size();
	for(int i = 0; i < n; i++){
		cnt[s[i]]++;
	}
	char ans1;
	int k = 123456789;
	for(auto i : cnt){
		if(i.second < k){
			k = i.second;
			ans1 = i.first;
		}
	}
	int ans2;
	for(int i = 0; i < n; i++){
		if(s[i] == ans1)ans2 = i + 1;
	}
	cout << ans2 << " " << ans1 << endl;
	return 0;
}
0