2 条题解

  • 5
    #include <iostream>
    #include <string>
    using namespace std;
    int main()
    {
    	string n;
    	cin >> n;
    	//如果为负数照常输出 
    	if(n[0] == '-')
    	{
    		cout << n << endl;
    	}
    	//如果为0照常输出 
    	else if(n == "0") cout << n << endl;
    	//如果为不是负数加上负号照常输出 
    	else
    	{
    		cout << "-" << n << endl;
    	}
    	return 0;
    }
    

    写了半天,试过了,也加了注释,点个赞在拿走吧

    • 0
      @ 2025-7-16 14:50:28

      #include #include using namespace std; int main() { string n; cin >> n; if(n[0] == '-') { cout << n << endl; } else if(n == "0") cout << n << endl; else { cout << "-" << n << endl; } return 0; }

      • 1

      信息

      ID
      7
      时间
      1000ms
      内存
      256MiB
      难度
      1
      标签
      递交数
      517
      已通过
      83
      上传者