
#include
#include
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;
}
这篇文章展示了如何使用C++编程语言处理用户输入,当输入为负数或零时,保持原样输出,否则添加负号。

#include
#include
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;
}

被折叠的 条评论
为什么被折叠?
