Question Name:EXPLORING RUINS

#include<iostream>
#include<string>
using namespace std;
int main()
{
string str;
cin>>str;
 
for(int i=0;i<str.size();i++)
{
if(str[i]=='a' || str[i]=='b')
continue;
if(str[i-1]=='a' || str[i+1]=='a')
str[i]='b';
else
str[i]='a';
}
cout<<str<<endl;
 
return 0;
}

  • Problem Description
    Little robot CJ-17 is exploring ancient ruins. He found a piece of paper with a word written on it. Fortunately, people who used to live at this location several thousand years ago used only two letters of modern English alphabet: ‘a’ and ‘b’. 

    It’s also known, that no ancient word contains two letters ‘a’ in a row. CJ-17 has already recognised some of the word letters, the others are still unknown.

    CJ-17 wants to look up all valid words that could be written on this paper in an ancient dictionary. He needs your help. Find him the word, which is the first in alphabetical order and could be written on the paper.

    Input format

    The first line contains non-empty string s consisting of ‘a’, ‘b’ and ‘?’ characters. Character ‘?’ corresponds to unrecognized letter.

    It’s guaranteed, that there exists at least one ancient word, that could be written on the paper.

    Constraints

    Length of s is at most 50.

    Output format

    Output the first in alphabetical order word, that could be written on the paper, found by CJ-17.
  • Test Case 1
    Input (stdin)
  • ?ba??b
    Expected Output
  • ababab
  • Test Case 2
    Input (stdin)
  • aba?b?
    Expected Output
  • ababba

Leave a Reply

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.