7 条题解

  • 2
    @ 2024-1-23 21:51:44
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
    	int n, a;
    	cin >> n;
    	if (n < 0)
        {
    		a = n - 1;
            cout << a << endl;
            return 0;
    	}
        if (n == 0)
        {
    		a = 0;
    	}
        else
        {
    		a = n + 1;
    	}
    	cout << a << endl;
        return 0;
    }
    // 谁有我代码长?
    
    • 1
      @ 2023-7-7 12:50:02
      #include<iostream>
      using namespace std;
      int main()
      {
      	int a;
      	cin>>a;
      	if(a==0)
      	{
      		cout<<0;
      	 } 
      	else if(a>0)
      	{
      		cout<<a+1;
      	}
      	else
      	{
      		cout<<a-1;
      	}
      	return 0;
      } 
      
    • 1
      @ 2022-12-23 11:23:20
      #include <bits/stdc++.h>
      using namespace std;
      int main()
      {
      	int n, a;
      	cin >> n;
      	if (n < 0)
          {
      		a = n - 1;
      	}
          else if (n == 0)
          {
      		a = 0;
      	}
          else
          {
      		a = n + 1;
      	}
      	cout << a << endl;
          return 0;
      }
      
      • 1
        @ 2022-11-10 13:13:30

        号没了

        #include <iostream>
        using namespace std;
        int main()
        {
            int x;
            cin >> x;
            if(x>0)
            {
                cout << x+1;
            }
            if(x<0)
            {
                cout << x-1;
            }
            else
            {
                cout << 0;
            }
        }
        
        • 0
          @ 2024-1-28 17:00:11

          题目既然说“求解编程中的分段函数”,咱们就用函数来解决这道题目吧,虽然我有点没看懂题目的意思😄~

          已AC,请放心食用

          #include <iostream>
          using namespace std;
          void deter(int x, int y)
          {
              if (x > 0)
              {
                  y = x + 1;
              }
              else if (x < 0)
              {
                  y = x - 1;
              }
              else
              {
                  y = 0;
              }
              cout << y;
          }
          int main()
          {
              int x, y;
              cin >> x >> y;
              deter(x, y);
              return 0;
          }
          

          养成好习惯,看后点个赞( •̀ ω •́ )✧!

          • 0
            @ 2023-8-31 15:09:23

            极其简单的代码,记得点个赞再抱走哦❤️

            #include <bits/stdc++.h>
            using namespace std;
            int main(){
                cout << -2;
                return 0;
            }
            
            • 0
              @ 2023-3-27 21:56:34

              判断三种情况

              #include<bits/stdc++.h>
              using namespace std;
              int main()
              {
                  int x;
                  cin>>x;
                  if (x>0)
                      cout<<x+1;
                  else if(x==0)
                      cout<<0;
                  else
                      cout<<x-1;
                  return 0;
              }
              
              • 1

              【入门】编程求解数学中的分段函数

              信息

              ID
              32
              时间
              1000ms
              内存
              16MiB
              难度
              2
              标签
              递交数
              273
              已通过
              170
              上传者