Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Signal from Space
- // One day a signal from space was registered. Scientists managed to record the signal as a sequence of N symbols. It turned out that due to a technical difficulty some symbols have been repeated. Help the scientists by writing a program which removes consecutive repetitions of symbols, decoding the message.
- // Input
- // Input data is read from the standard input
- // On the only input line, a message is given
- // Output
- // Print to the standard output
- // Print the decoded message
- // Constraints
- // The length of the message will be no more than 10000 symbols
- // Message consists of digits and Latin letters (upper and lower case)
- // Sample tests
- // Input
- // Hello
- // Output
- // Helo
- // Input
- // hoboobbo422222Aaao
- // Output
- // hobobo42Aao
- const input = ['Helloo'];
- const print = this.print || console.log;
- const gets = this.gets || ((arr, index) => () => arr[index++])(input, 0);
- const initialSignalLength = gets();
- let translatedSignal = '';
- for (let i = 0; i < initialSignalLength.length; i++) {
- if (initialSignalLength[i] !== initialSignalLength[i + 1]) {
- translatedSignal += initialSignalLength[i];
- } else {
- continue;
- }
- }
- print(translatedSignal);
Advertisement
Add Comment
Please, Sign In to add comment