A. Broken Keyboard-----思维(稍水)

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.

Input
The first line contains one integer t (1≤t≤100) — the number of test cases in the input.

Then the test cases follow. Each test case is represented by one line containing a string s consisting of no less than 1 and no more than 500 lowercase Latin letters.

Output
For each test case, print one line containing a string res. The string res should contain all characters which correspond to buttons that work correctly in alphabetical order, without any separators or repetitions. If all buttons may malfunction, res should be empty.

Example
inputCopy

4
a
zzaaz
ccff
cbddbb
outputCopy
a
z

bc

题意:有一些好的按键和一些坏的按键,按好的出现一个字符,按坏的末尾会出现两个字符,问你哪些是好的。

解析:只要判断字符是不是连续出现2次,就行了。


#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
map<int,int> v,mp;
vector<int > ans;
char s[1000005];
int t;
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>(s+1);
		int n=strlen(s+1);
		ans.clear();
		v.clear();
		if(n==1)
		{
			cout<<(s+1)<<endl;
			continue;
		}
		for(int i=1;i<=n;i++)
		{
			if(s[i]==s[i+1]) i++;
			else
			{
				if(v[s[i]-'a']==0)
				{
					ans.push_back(s[i]-'a');
					v[s[i]-'a']=1;
				}
			}
		}
	
		sort(ans.begin(),ans.end());
		n=ans.size();
		for(int i=0;i<n;i++) 
		{
			printf("%c",ans[i]+'a');
		}
		cout<<endl; 
	}
 } 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. spyder 5.4.1 requires pyqt5<5.16, which is not installed. spyder 5.4.1 requires pyqtwebengine<5.16, which is not installed. Successfully installed aiofiles-23.1.0 altair-4.2.2 blinker-1.6.2 cachetools-5.3.1 chardet-5.1.0 cmake-3.26.3 cpm_kernels-1.0.11 fastapi-0.95.2 ffmpy-0.3.0 gitdb-4.0.10 gitpython-3.1.31 gradio-3.32.0 gradio-client-0.2.5 h11-0.14.0 httpcore-0.17.2 httpx-0.24.1 latex2mathml-3.76.0 linkify-it-py-2.0.2 lit-16.0.5 markdown-it-py-2.2.0 mdit-py-plugins-0.3.3 mdtex2html-1.2.0 mdurl-0.1.2 nvidia-cublas-cu11-11.10.3.66 nvidia-cuda-cupti-cu11-11.7.101 nvidia-cuda-nvrtc-cu11-11.7.99 nvidia-cuda-runtime-cu11-11.7.99 nvidia-cudnn-cu11-8.5.0.96 nvidia-cufft-cu11-10.9.0.58 nvidia-curand-cu11-10.2.10.91 nvidia-cusolver-cu11-11.4.0.1 nvidia-cusparse-cu11-11.7.4.91 nvidia-nccl-cu11-2.14.3 nvidia-nvtx-cu11-11.7.91 orjson-3.8.14 protobuf-3.20.3 pydantic-1.10.8 pydeck-0.8.1b0 pydub-0.25.1 pygments-2.15.1 pympler-1.0.1 python-multipart-0.0.6 rich-13.4.1 semantic-version-2.10.0 sentencepiece-0.1.99 smmap-5.0.0 starlette-0.27.0 streamlit-1.22.0 streamlit-chat-0.0.2.2 torch-2.0.1 transformers-4.27.1 triton-2.0.0 tzlocal-5.0.1 uc-micro-py-1.0.2 uvicorn-0.22.0 validators-0.20.0 websockets-11.0.3 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv 解释下
最新发布
06-02

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值