我正在编写一些代码,其中我想(逐字逐句地)将以下句子的变体拼凑在一起,但我正在处理我的“if”和“else if”的用法
You are in a twisting little maze of passages, all different.事实上,我总共有12句话要说:
You are in a twisting little maze of passages, all different.
You are in a little twisting maze of passages, all different.
You are in a twisty little maze of passages, all different.
You are in a little twisty maze of passages, all different.
You are in a little maze of twisting passages, all different.
You are in a little maze of twisty passages, all different.
You are in a twisting maze of little passages, all different.
You are in a twisty maze of little passages, all different.
You are in a maze of twisting little passages, all different.
You are in a maze of little twisting passages, all different.
You are in a maze of twisty little passages, all different.
You are in a maze of little twisty passages, all different.我使用的变量如下:
1) int little / 2) int twist / 3) int twisting / 4) int before它们的职能如下:
我有以下思路:
#include <stdio.h>
void mazesentence(int little, int twist, int twisting, int before)
{
printf("You are in a ");
if(little == 0 && twist == 0)
{
if(before == 0)
{
if(twisting == 0)
printf("twisty ");
else if(twisting == 1);
printf("twisting ");
printf("little ");
}
else if(before == 1)
printf("little ");
if(twisting == 0)
printf("twisty ");
else if(twisting == 1);
printf("twisting ");
printf("of maze ");
}
if(little == 1 && twist == 1)
{
if(before == 0)
{
if(twisting == 0)
printf("twisty ");
else if(twisting == 1);
printf("twisting ");
printf("little");
}
else if(before == 1)
printf("little ");
if(twisting == 0)
printf("twisty ");
else if(twisting == 1);
printf("twisting ");
printf("passages");
}
printf("passages, all different.\n");
return;
}
int main( )
{
mazesentence(0, 0, 1, 0);
mazesentence(0, 0, 1, 1);
mazesentence(0, 0, 0, 0);
mazesentence(0, 0, 0, 1);
mazesentence(0, 1, 1, 0);
mazesentence(0, 1, 0, 0);
mazesentence(1, 0, 1, 0);
mazesentence(1, 0, 0, 0);
mazesentence(1, 1, 1, 0);
mazesentence(1, 1, 1, 1);
mazesentence(1, 1, 0, 0);
mazesentence(1, 1, 0, 1);
return 0;
}但是,输出如下:
You are in a twisting little twisting of maze passages, all different.
You are in a little twisting of maze passages, all different.
You are in a twisty twisting little twisty twisting of maze passages, all different.
You are in a little twisty twisting of maze passages, all different.
You are in a passages, all different.
You are in a passages, all different.
You are in a passages, all different.
You are in a passages, all different.
You are in a twisting littletwisting passagespassages, all different.
You are in a little twisting passagespassages, all different.
You are in a twisty twisting littletwisty twisting passagespassages, all different.
You are in a little twisty twisting passagespassages, all different.这12句话需要与上述12句话相匹配。除了额外的“扭曲”,第一句几乎是一样的。我做错了什么?
发布于 2021-03-24 00:59:57
代码中有一些错误,逻辑中也有其他错误:
否则如果(扭曲== 1);打印(“扭曲");
这是正确的使用方法:
否则,如果(扭转== 1) printf(“扭曲");
我稍微修改了一下您的代码,它正在工作:
void mazesentence(int little, int twist, int twisting, int before)
{
printf("You are in a ");
if(twist == 0)
{
if(before == 0){
if (twisting == 0){
printf("twisty ");
} else if (twisting == 1){
printf("twisting ");
}
if(little == 0){
printf("little ");
}
}else if(before == 1){
if(little == 0){
printf("little ");
}
if(twisting == 0)
printf("twisty ");
else if(twisting == 1)
printf("twisting ");
}
printf("maze of ");
if(little == 1){
printf("little ");
}
}else if(twist == 1){
if(little == 0){
printf("little maze of ");
if(before == 1){
if(twisting == 0)
printf("twisty ");
else if(twisting == 1)
printf("twisting ");
}
}else if(little == 1){
printf("maze of ");
if(before == 1){
printf("little ");
if(twisting == 0)
printf("twisty ");
else if(twisting == 1)
printf("twisting ");
}else if(before == 0){
if(twisting == 0)
printf("twisty ");
else if(twisting == 1)
printf("twisting ");
printf("little ");
}
}
}
printf("passages, all different.\n");
return;
}
int main( )
{
mazesentence(0, 0, 1, 0);
mazesentence(0, 0, 1, 1);
mazesentence(0, 0, 0, 0);
mazesentence(0, 0, 0, 1);
mazesentence(0, 1, 1, 1);
mazesentence(0, 1, 0, 1);
mazesentence(1, 0, 1, 0);
mazesentence(1, 0, 0, 0);
mazesentence(1, 1, 1, 0);
mazesentence(1, 1, 1, 1);
mazesentence(1, 1, 0, 0);
mazesentence(1, 1, 0, 1);
return 0;
}https://stackoverflow.com/questions/66771351
复制相似问题