forked from imdhanish/HackerEarth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExploring_Ruins.cpp
More file actions
59 lines (57 loc) · 1.5 KB
/
Exploring_Ruins.cpp
File metadata and controls
59 lines (57 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*************************************************
* *
* author : Sanjeev Sharma *
* GitHub : github.com/thedevelopersanjeev *
* Contact : thedevelopersanjeev@gmail.com *
* *
*************************************************/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string str;
char c;
cin >>str;
if(str == "?"){
cout <<"a";
}
else{
for(int i=0; i<str.length(); i++){
c = str.at(i);
if(i == str.length()-1 && c == '?' && str.at(i-1) != 'a'){
// replace last character by 'a'
str[str.length()-1] = 'a';
}
else if(i == str.length()-1 && c == '?'){
// replace last character by 'b'
str[str.length()-1] = 'b';
}
else if(i == 0 && c == '?' && str.at(i+1) == 'a'){
// replace first character by 'b'
str[0] = 'b';
}
else if(i == 0 && c == '?'){
// replace first character by 'a'
str[0] = 'a';
}
else if(c == '?' && str.at(i-1) == 'a'){
// replace character at i by 'b'
str[i] = 'b';
}
else if(c == '?' && str.at(i+1) == 'a'){
// replace character at i by 'b'
str[i] = 'b';
}
else if(c == '?'){
// replace character at i by 'a'
str[i] = 'a';
}
else{
// do nothing
}
}
cout <<str;
}
return 0;
}