[CF] A. Broken Keyboard - Educational Codeforces Round 75 (Rated for Div. 2)
Solutions Codeforces 双指针 1000 Easy-
Lastmod: 2025-01-12 周日 23:26:35

https://codeforces.com/contest/1251/problem/A

题目大意

给出一个小写字母组成的字符串 $S \ (|S| \le 500)$。这是一个测试键盘的打字产生的序列,当一个字母对应的键是坏的时,会连续插入两个对应的字符。问从测试序列能推出那些字符确定是好的,字典序输出。

简要题解

显然对于同一字母的一段,如果是奇数长则其一定是好的。

复杂度

$T$:$O(|S|)$

$S$:$O(|S|)$

代码实现

#include <bits/stdc++.h>
using namespace std;

int io_=[](){ ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();

using LL = long long;
using ULL = unsigned long long;
using LD = long double;
using PII = pair<int, int>;
using VI = vector<int>;
using MII = map<int, int>;

template<typename T> void cmin(T &x,const T &y) { if(y<x) x=y; }
template<typename T> void cmax(T &x,const T &y) { if(x<y) x=y; }
template<typename T> bool ckmin(T &x,const T &y) { 
    return y<x ? (x=y, true) : false; }
template<typename T> bool ckmax(T &x,const T &y) { 
    return x<y ? (x=y, true) : false; }
template<typename T> void cmin(T &x,T &y,const T &z) {// x<=y<=z 
    if(z<x) { y=x; x=z; } else if(z<y) y=z; }
template<typename T> void cmax(T &x,T &y,const T &z) {// x>=y>=z
    if(x<z) { y=x; x=z; } else if(y<z) y=z; }

// mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
// mt19937_64 rnd_64(chrono::system_clock::now().time_since_epoch().count());

/*
---------1---------2---------3---------4---------5---------6---------7---------
1234567890123456789012345678901234567890123456789012345678901234567890123456789
*/

void solve() {
  string s; cin >> s;
  int n = s.length();
  set<char> se;
  for (int i = 0; i < n; ) {
    int j = i;
    while (j < n && s[j] == s[i]) j++;

    if ((j - i) & 1) {
      se.insert(s[i]);
    }
    i = j;
  }

  for (char c : se) cout << c;
  cout << '\n'; 
}

int main() {
  int t = 1; 
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
Prev: [CF] A. You Are Given Two Binary Strings... - Educational Codeforces Round 70 (Rated for Div. 2)
Next: [CF] D. Array Collapse - Educational Codeforces Round 160 (Rated for Div. 2)