zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 75 (Rated for Div. 2) A. Broken Keyboard

    链接:

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

    题意:

    Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning.

    To check which buttons need replacement, Polycarp pressed some buttons in sequence, and a string s appeared on the screen. When Polycarp presses a button with character c, one of the following events happened:

    if the button was working correctly, a character c appeared at the end of the string Polycarp was typing;
    if the button was malfunctioning, two characters c appeared at the end of the string.
    For example, suppose the buttons corresponding to characters a and c are working correctly, and the button corresponding to b is malfunctioning. If Polycarp presses the buttons in the order a, b, a, c, a, b, a, then the string he is typing changes as follows: a → abb → abba → abbac → abbaca → abbacabb → abbacabba.

    You are given a string s which appeared on the screen after Polycarp pressed some buttons. Help Polycarp to determine which buttons are working correctly for sure (that is, this string could not appear on the screen if any of these buttons was malfunctioning).

    You may assume that the buttons don't start malfunctioning when Polycarp types the string: each button either works correctly throughout the whole process, or malfunctions throughout the whole process.

    思路:

    枚举长度, 只要有连续奇数字符,就满足条件。

    代码:

    #include<bits/stdc++.h>
    using namespace std;
     
    int main()
    {
        ios::sync_with_stdio(false);
        string s;
        int t;
        cin >> t;
        while(t--)
        {
            cin >> s;
            set<char> res;
            for (int i = 0, j;i < (int)s.length();i=j+1)
            {
                j = i;
                for (;j < (int)s.length();j++)
                {
                    if (s[j] != s[i])
                    {
                        j--;
                        break;
                    }
                }
                j = min((int)s.length()-1, j);
                if ((j-i+1)%2)
                    res.insert(s[i]);
            }
            for (auto v: res)
                cout << v;
            cout << endl;
        }
     
        return 0;
    }
    
  • 相关阅读:
    wpf中显示HTML(转自http://steeven.cnblogs.com/archive/2006/06/12/424258.html)
    【msdn wpf forum翻译】TextBox中文本 中对齐 的方法
    【msdn wpf forum翻译】TextBlock等类型的默认样式(implicit style)为何有时不起作用?
    《Applications=Code+Markup》读书笔记 1(第一章 初识Application和Window)
    sql 分页
    Api
    快钱接口
    c#经典面试题
    static/const/readonly
    静态构造函数和静态类
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11779029.html
Copyright © 2011-2022 走看看