From 1fb8d1da1bca5a43fc9d5f86a2366063b80afe76 Mon Sep 17 00:00:00 2001 From: Akshat Joshi <39386084+AkshatJoshi2000@users.noreply.github.com> Date: Tue, 24 Sep 2019 14:38:25 +0530 Subject: [PATCH] Create Q11.cpp --- Q11.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Q11.cpp diff --git a/Q11.cpp b/Q11.cpp new file mode 100644 index 0000000..7043b1a --- /dev/null +++ b/Q11.cpp @@ -0,0 +1,38 @@ +#include +#include +using namespace std; + +char g(queue &q, int v[]) { + while(!q.empty()) { + if (v[q.front()-'a'] > 1) { + q.pop(); + } else { + return q.front(); + } + } + return 'Z'; +} + +int main() { + int s; + cin >> s; + while(s--) { + int n; + cin >> n; + char s[n]; + for (int i=0; i < n; i++) cin >> s[i]; + queue q; + int f[26] = {0}; + for (int i=0; i < n; i++) { + f[s[i]-'a'] ++; + if (f[s[i]-'a'] < 2) { + q.push(s[i]); + } + char ch = g(q,f); + if (ch == 'Z') cout << "0 "; + else cout << ch << " "; + } + cout << '\n'; + } + return 0; +}