我写了一个,但答案不对,希望帮忙改一下,谢谢

我们已经知道了将N个整数按从小到大排序的冒泡排序法。本题要求将此方法用于字符串序列,并对任意给定的K(<N),输出扫描完第K遍后的中间结果序列。

输入格式:
输入在第1行中给出N和K(1≤K<N≤100),此后N行,每行包含一个长度不超过10的、仅由小写英文字母组成的非空字符串。

输出格式:
输出冒泡排序法扫描完第K遍后的中间结果序列,每行包含一个字符串。

输入样例:
6 2
best
cat
east
a
free
day

输出样例:
best
a
cat
day
east
free

以下是我的代码
#include
#include
using namespace std;
#define max 10000
int main()
{
string str[max],str1;
int i,n,k,j,m,l;
cin>>n>>k;
for(i=0;i {
str[i]=cin.get();
}
for(j=0;j for(m=0;m {
if(str[m]>str[m+1])
{
str1=str[m];
str[m]=str[m+1];
str[m+1]=str1;
}
}
}

for(l=0;l<n;l++)
{
    cout<<str[l]<<endl;
}

}

// Q1058158.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <string>
using namespace std;
#define max 10000
int main()
{
    string str[max],str1;
    int i,n,k,j,m,l;
    cin>>n>>k;
    for(i=0;i <n;i++){
        cin >> str[i];
    }
    for(j=0;j<n-1;j++) {
        for(m=0;m<n-j-1;m++) {
            if(str[m]>str[m+1])
            {
                str1=str[m];
                str[m]=str[m+1]; 
                str[m+1]=str1;
            }
        }
        if (j == k-1)
        {
            for(l=0;l<n;l++)
            {
                cout<<str[l]<<endl;
            }
        }
    }
    //for(l=0;l<n;l++)
    //{
    //  cout<<str[l]<<endl;
    //}
}