Kattis-Apaxiaaaaaaaaaaaans!

Posted 做一个AC梦

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kattis-Apaxiaaaaaaaaaaaans!相关的知识,希望对你有一定的参考价值。

题目所述基本内容

The ancient and mysterious Apaxian civilization, which we most certainly did not make up, continues to confound the researchers at the Oriental Institute. It turns out that the Apaxians had a peculiar naming system: the more letters in your name, the higher your status in society. So, in Apaxian society, robert was probably a lowly servant, and robertapalaxiamethostenes was likely a High Priest or Minister. Even more than that, Apaxians valued the number of adjacent letters that were the same in a name. So, while robert continues to be an unimpressive  name, roooooooooobert probably elicited cheers and applause wherever he went.

Unfortunately, this makes the task of reading Apaxian scrolls very cumbersome, especially when you consider that a particularly famous Apaxian queen had ten thousand consecutive a’s in her name. Legend has it that she was already two years old by the time the Royal Herald finished announcing her birth.

To make the Oriental Institute’s life easier, the Department of Computer Science has offered to convert the Apaxian scrolls into a more readable format. Specifically, we will be taking Apaxian names and replacing all consecutive runs of the same letter by a single instance of such letter.

So, for example, the compact version of roooobert would be robert, where the four consecutive o’s have been replaced with a single o. Similarly, the compact version of rrrooobbbert would also be robert. On the other hand, the compact version of robert is still robert.

输入输出样例

Input

The input contains a single name. Each name contains only lowercase letters (a–z), no whitespace, a minimum length of 1 character, and a maximum length of 250 characters.

Output

The output contains the compact version of the name: any time the same letter appears two or more times in sequence, it must be replaced by a single instance of that letter.

 

代码

#include<iostream>
#include<string>
#include<map>
using namespace std;

int main() 
	string str;
	map<char, int>p;
	cin >> str;
	char t=str[0];
	for (int i = 0; i <str.length(); i++) 
		p[str[i]]++;
		if (t != str[i]) 
			p[t] = 0;
		
		if (p[str[i]] == 1) 
			t = str[i];
			cout << str[i];
		
	

结束语

好兄弟好兄弟,留下你的关注和点赞,666走一波!!!!!

以上是关于Kattis-Apaxiaaaaaaaaaaaans!的主要内容,如果未能解决你的问题,请参考以下文章