C++ if语句练习题

img


刚学if语句 跟同学想了这么个题 结果我俩 自己不会做
我感觉是用bool和if语句嵌套吧.()苦于不知道怎么写

字符串判断,如果等于,则打印输出对应的中文

img


#include <bits/stdc++.h>

using namespace std;

int main()
{
    string str;
    getline(cin,str);
    if(str=="north east"||str=="east north"){
        cout<<"东北"<<endl;
    }else if(str=="east south"||str=="south east"){
    cout<<"东南"<<endl;
    }else if(str=="north west"||str=="west north"){
    cout<<"西北"<<endl;
    }else{
        cout<<"西南"<<endl;
    }
    return 0;
}