Question
C code. Needs 7 passwords that meet the conditions of each part and do not trigger an explosion. The first code is Be Careful, the
C code. Needs 7 passwords that meet the conditions of each part and do not trigger an explosion. The first code is "Be Careful", the second code is "110", and the third code is "XXa". Can you please tell me the other codes? I will upvote for your effort!!
#include
#include
#include
void explode(const int code)
{
printf("exploded! ");
exit(code);
}
void readInput(char buffer[], const int bufferSize)
{
int i;
int c;
for (i = 0; i <= bufferSize; ++i)
{
c = getchar();
if (c == ' ')
{
c = getchar();
}
if (c == ' ')
{
break;
}
else if (i < bufferSize)
{
buffer[i] = (char)c;
}
}
}
void part1()
{
const int bufferSize = 12;
char buffer[bufferSize];
char target[] = "Be Careful";
int i;
const int n = strlen(target);
readInput(buffer, bufferSize);
for (i = 0; i < n; i++)
{
if (buffer[i] != target[i])
{
explode(1);
}
}
}
int part2()
{
int i, z;
const int bufferSize = 12;
char buffer[bufferSize];
readInput(buffer, bufferSize);
z = atoi(buffer);
if (!z)
explode(10);
z -= 17;
if (z != 93)
explode(21);
return z / 2;
}
void part3()
{
int i, z;
const int bufferSize = 12;
char buffer[bufferSize];
readInput(buffer, bufferSize);
i = 0;
while (i < bufferSize && (buffer[i] == 'X' || buffer[i] == 'a'))
{
i++;
}
if (i != 3)
explode(20);
}
void part4(const int x)
{
int i, y, z;
const int bufferSize = 12;
char buffer[bufferSize];
readInput(buffer, bufferSize);
z = atoi(buffer);
if (!z)
explode(30);
y = z;
for (i = 0; i < 50; i++)
{
y += z * i * y;
}
if (z + 9 != x)
{
explode(31);
}
}
void part5(char buffer[], const int bufferSize)
{
const char allowed[] = "az3hoPeACce6";
int i, j, x;
for (i = 0; i < bufferSize; ++i)
{
char c;
x = getchar();
if (x == EOF)
explode(10);
else if (x == ' ')
explode(41);
c = (char)x;
for (j = 2; j < 10; ++j)
{
if (c == allowed[j])
{
buffer[i] = c + 1;
break;
}
}
if (j == 10)
{
explode(51);
}
}
j = 0;
for (i = 1; i < bufferSize; ++i)
{
if (buffer[i] != buffer[i - 1])
{
j = 1;
break;
}
}
if (j == 0)
explode(61);
x = getchar();
if (x == ' ')
x = getchar();
if (x != ' ')
explode(64);
}
void part6(const char buf1[], const int bufSize)
{
char buf2[bufSize];
int i, c;
readInput(buf2, bufSize);
for (i = 0; i < bufSize; ++i)
{
if (buf1[i] != buf2[bufSize - 1 - i])
explode(-77);
}
}
void part7(int *x)
{
int y = 29;
int *z = &y;
int k;
const int bufSize = 12;
char buffer[bufSize];
*z -= 3;
readInput(buffer, bufSize);
k = atoi(buffer);
if (k + *x != y)
explode(80);
}
void theBomb()
{
const int bufSize = 10;
char buffer[bufSize];
int result;
printf("Enter the stage 1 password: ");
part1();
printf("Stage 1 defused. ");
printf("Enter the stage 2 password: ");
result = part2();
printf("Stage 2 defused. ");
printf("Enter the stage 3 password: ");
part3();
printf("Stage 3 defused. ");
printf("Enter the stage 4 password: ");
part4(result);
printf("Stage 4 defused. ");
printf("Enter the stage 5 password: ");
part5(buffer, bufSize);
printf("Stage 5 defused. ");
printf("Enter the stage 6 password: ");
part6(buffer, bufSize);
printf("Stage 6 defused. ");
printf("Enter the stage 7 password: ");
part7(&result);
printf("Stage 7 defused. ");
printf("The entire bomb has been defused. ");
}
int main()
{
bomb();
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started