Sticky Keys
Time limit1sMemory limit1024 MB
Given a line of letters, digits, and spaces, collapse each run of identical consecutive characters into a single character and print the result.
- Level
Easy1 of 10
- Topics
- String, Implementation
- Solved
- No attempts yet
Problem
Bob is texting Alice about his favourite programming problems, but he spilled coffee on his keyboard and now the keys get stuck when he types. The other day, he tried to tell her about the upcoming contest "UAPC", but he accidentally sent "UAAAAAPC" because his A key got stuck. Bob is an undergraduate and cannot afford a new keyboard, so he asked you to write a program that corrects his messages.
Bob has agreed to avoid messages with adjacent copies of the same letter (for example, he will not write about the "coffee" incident). So you should always reduce runs of repeated characters down to a single character.
Input
The input is a string , where , which is Bob's entire message to Alice. The message may contain several space-separated words, and the whole string, including spaces, is part of the message.
contains only upper and lower-case letters, digits, and spaces. The coffee did not reach the spacebar, so there are never two spaces in a row.
Output
Output the message with each run of repeated consecutive characters trimmed to a single character.