C++中bool类型输出成true或者false,而不是1,0

leetcode657

#include <bits/stdc++.h>

using namespace std;
bool judgeCircle(string moves){
    int up=0;
    int lr=0;

    for(int i=0;i<moves.length();i++){
        if(moves[i]=='U') up++;
        if(moves[i]=='D') up--;
        if(moves[i]=='L') lr++;
        if(moves[i]=='R') lr--;
    }

    if(up==0 && lr==0){
        return true;
    }else{
        return false;
    }

}

int main()
{
    string str;
    cin>>str;
    //把bool型输出成true或者false 而不是 1,0
    cout<<boolalpha<<judgeCircle(str)<<endl;
    return 0;
}


发布了38 篇原创文章 · 获赞 43 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/qq_40272386/article/details/80180744