如何将前面的“0”从上面的数字10中删除?只有1-9号应该在“0”之前。
样本输入: 40
样本产量:01.02.03.04.05.07.08.09.10 11.12.13.14.16.17.18.19.20 21.22.24.25.27.28.30 31.32.33.35.36.38.39.40
我的代码输出:01.02.03.04.05.06.07.09.010 011.012.013.014.015.017.018.019.020 021.022.023.024.026.029.030 031.032.033.035.036.038.039.040
你能帮帮我吗?我试过不同的方法,但还是行不通。我是编程新手,这就是我不太懂的原因。
这是我的密码:
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> b;
if (b > 100){
cout << "OUT OF RANGE";
}
else {
for (int a = 1; a <= b; a++){
cout << "." << "0" << a;
}
}
}
发布于 2021-09-28 03:09:23
std::cout <<"." << std::setfill('0') << std::setw(2) << a;
https://stackoverflow.com/questions/69355295
复制相似问题