// Need to know what string to enter so that the explode(#) method calls never e
ID: 3887343 • Letter: #
Question
//Need to know what string to enter so that the explode(#) method calls never execute. I've tried string = "hUD6Cc8b" and during debugging I always run into the explode(10) || explode(11)
void part5(char buffer[], const int bufferSize){
const char allowed[] = "a3hUD6Cc8bTzv";
int i, j, x;
for(i=0; i<bufferSize; ++i){
char c;
x = getchar();
if(x == EOF)
explode(10);
else if(x == ' ')
explode(11);
c = (char)x;
for(j=2; j<10; ++j){
if(c == allowed[j]){
buffer[i] = c + 1;
break;
}
}
if(j == 10){
explode(12);
}
}
j = 0;
for(i=1; i<bufferSize; ++i){
if(buffer[i] != buffer[i-1]){
j = 1;
break;
}
}
if(j == 0)
explode(13);
/* Windows encodes an end-of-line as two characters: */
/* Linux just uses */
/* This will accept either version */
x = getchar();
if(x == ' ')
x = getchar();
if(x != ' ')
explode(14);
}
Explanation / Answer
The input character must match one of the character in "huD6Cc8b" and the other important thing is that these characters are getting stored in the buffer with one increment. The sigificant thing is no two adjacent items in buffer should be same. It is certain that we need to repeat the inputs as the outer loop is running for the buffer size. We should repeat the characters but what we need to be careful is that repeatitions should not be adjacent.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.