为什么会报错:Standard answer longer than user output.
题目描述
输入 n 个 1∼2000 范围内的整数。
将其从小到大进行插入排序,第 i 步将 a[i] 插入到合适的位置,输出每个元素插入后的状态。
输入格式
第一行一个整数 n。
接下来一行 n 个整数,含义如题意所述。
5
7 6 3 8 2
输出格式
n 行每行 n 个空格隔开的整数,含义如题意所述。
7 6 3 8 2
6 7 3 8 2
3 6 7 8 2
3 6 7 8 2
2 3 6 7 8
数据规模与约定
对于 100% 的数据,1≤n≤100。
#include <bits/stdc++.h>
using namespace std;
int a[110];
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i ++ )
cin >> a[i];
for (int i = 1; i < n; i ++ )
{
if(a[i] < a[i - 1])
{
int temp = a[i];
int j = i - 1;
for( ;j >= 0 && temp < a[j]; j -- )
{
a[j + 1] = a[j];
}
a[j + 1] = temp;
}
for(int k = 0; k < n; k ++ )
{
cout << a[k] << ' ';
}
cout << endl;
}
return 0;
}