From c4a4e8ba38938013b88dcdcb7601a8f291450c48 Mon Sep 17 00:00:00 2001 From: Ren Baoshuo Date: Mon, 2 Aug 2021 19:52:39 +0800 Subject: [PATCH] =?UTF-8?q?772.=20=E5=8F=AA=E5=87=BA=E7=8E=B0=E4=B8=80?= =?UTF-8?q?=E6=AC=A1=E7=9A=84=E5=AD=97=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acwing.com/problem/content/submission/code_detail/6847872/ --- AcWing/772/772.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 AcWing/772/772.cpp diff --git a/AcWing/772/772.cpp b/AcWing/772/772.cpp new file mode 100644 index 00000000..a1a3953d --- /dev/null +++ b/AcWing/772/772.cpp @@ -0,0 +1,33 @@ +#include + +using namespace std; + +int main() { + string s; + vector ans; + int a = -1; + char c = 'a'; + cin >> s; + map m, m1; + for (int i = 0; i < s.size(); i++) { + m[s[i]]++; + if (!m1.count(s[i])) m1[s[i]] = i; + } + for (char i = 'a'; i <= 'z'; i++) { + if (m[i] == 1) { + ans.push_back(i); + } + } + if (ans.empty()) { + cout << "no" << endl; + } else { + for (char i : ans) { + if (a == -1 || m1[i] < a) { + a = m1[i]; + c = i; + } + } + cout << c << endl; + } + return 0; +}