先贴上代码
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <vector>
void TLE(int &n) {
int t = 1;
for (int i = n; i >= 0; i--) {
for (int j = 1; j <= i; j++, t++) {
printf("%02d", t);
}
printf("\n"); // 注意这一行
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
int n;
std::cin >> n;
TLE(n);
return 0;
}
代码中注释的地方我试着改成std::cout << '\n';结果就是全部一行打印一通然后换很多次行,特别奇怪;然后我把这行改成std::cout << std::endl;的话就多输出一行,然后就全WA,最后改成了上面的AC代码的写法才全对
不明白这几种输出方式的区别在哪里?特别是std::cout << '\n';为什么会出现那种问题