11 条题解

  • 3
    @ 2023-7-1 21:27:27

    一个判断就好了

    • 3
      @ 2023-7-1 21:26:29
      #include <iostream>
      using namespace std;
      int main()
      {
          int q;
          cin>>q;
          cout<<(q!=0);
          return 0;
      }
      
      • 1
        @ 2024-5-5 9:40:53
        //换个思路,用判断结构。
        #include <iostream>
        using namespace std;
        int main()
        {
            int a;
            cin >> a;
            /*把int类型转换成bool类型时,
            如果int类型是0,则bool类型是False,
            否则,bool类型是True。
            反之亦然。
            (True转换成int类型是1。)*/
            //判断
            if(a == 0)//是0
            {
                cout << 0;//输出0
            }
            else//不是0
            {
                cout << 1;//输出1
            }
            return 0;
        }
        //编写不易,请勿抄袭!
        
        • 1
          @ 2024-4-18 22:00:49
          #include <iostream>
          using namespace std;
          int main()
          {
              int q;
              cin>>q;
              cout<<(q!=0);
              return 0;
          }
          
          
          • 1
            @ 2023-8-4 22:17:01
            #include<bits/stdc++.h>
            using namespace std;
            int main()
            {
                int a;
                cin>>a;
                bool c=a;
                int d=c;
                cout<<d;
                return 0;
            }
            

            🤭这是一道转换题,细心点就行啦!

            • 0
              @ 2024-4-14 16:13:59
              #include <iostream>
              using namespace std;
              int main()
              {
                  int a,b;
                  bool c;
                  cin >> a;
                  c = a;
                  b = c;
                  cout <<b;
                  return 0;
              }
              //根据题目要求说的即可,bool是布尔类型
              
              • 0
                @ 2024-4-1 17:42:16
                #include <iostream>
                using namespace std;
                int main()
                {
                    cout<<1;
                    return 0;
                }
                

                其实这样就可以过关了

              • 0
                @ 2023-5-22 20:01:30

                解析

                按照题目要求先从int类型强转到bool类型,再从bool类型强转到int类型,即 int → bool → int。

                参考代码

                #include <iostream>
                using namespace std;
                int n;
                bool m;
                int main()
                {
                    cin >> n;
                    m = n; // 将整型变量的值赋值给布尔型变量
                    n = m; // 将布尔型变量的值赋值给整型变量 
                    cout << n;
                    return 0;
                }
                
                • 0
                  @ 2023-5-21 19:39:34

                  没啥好说的强制转换即可

                  #include<stdio.h>
                  int main() {
                      int a;
                      bool b;
                      scanf ("%d",&a);
                      b=a;
                      printf ("%d",b);
                      return 0;
                  }
                  
                  
                  
                  • 0
                    @ 2023-5-21 0:54:51
                    #include<bits/stdc++.h>
                    using namespace std;
                    int main()
                    {
                    	int a;
                    	cin >> a;
                    	if (a != 0) cout << 1;
                    	else cout << 0;
                    	return 0;
                    }
                    
                    • 0
                      @ 2023-5-20 22:37:46

                      #include<stdio.h> #include<stdbool.h> int main() { int a; bool b; scanf("%d",&a); b=a; printf("%d\n",b); return 0; }

                      • @ 2023-5-20 22:38:13

                        第一次发 不大会

                      • @ 2023-5-21 19:38:52

                        @ 发题解时你可以点击</> 就是代码块然后就会出现3个` 在后面加上cpp 换行加上代码就行了

                    • 1

                    信息

                    ID
                    89
                    时间
                    1000ms
                    内存
                    128MiB
                    难度
                    1
                    标签
                    递交数
                    266
                    已通过
                    195
                    上传者