北大 acm 1007

来源:百度知道 编辑:UC知道 时间:2024/06/05 05:42:16
先声明一下 我大一的 刚刚接触这个……
我用C编的,自己试的都可以
就是输入10 6的时候,也就是题目举例的,他就出问题了
希望高手能帮忙看一下
#include<stdio.h>
#include<string.h>
void main()
{
int i,j,k,temp;char a[20][20]={0};
int b[20]={0};
int x,y;
scanf("%d%d",&y,&x);
for(i=1;i<=x;i++)
{ for(j=0;j<=y;j++)
scanf("%c",&a[i][j]);
}
for(i=1;i<=x;i++)
{
for(j=1;j<=y;j++)
{
for(k=j+1;k<=y;k++)
{
if(a[i][j]>a[i][k])
b[i]=b[i]+1;
}
}
}
for(j=0;j<=y;j++)
{
for(i=1;i<x;i++)
{
if(b[i+1]<b[i])
{
for(k=1;k<=y;k++)
{
temp=a[i+1][k];
a[i+1][k]=a[i][k];
a[i][k]=temp;
temp=b[i+1];
b[i+1]=b[i];
b[i]=temp;
}
}
}
}
for(i=1;i<=x;i++)
{
for(j=1;j<=y;j++)
printf(&q

#include <iostream>
#include <string>
using namespace std;
struct dna {
int inver;
string s;
} st[120],ste;
int main (void)
{
int n,m,i,j,k;
cin >>n >>m;
for (i=0;i<m;i++) {
cin >>st[i].s;
for (j=0;j<n-1;j++){
for(k=j+1;k<n;k++){
if (st[i].s[j]>st[i].s[k])
st[i].inver ++;
}
}

}
for (i=0;i<m-1;i++) {
for (j=i+1;j<m;j++){
if (st[i].inver>st[j].inver ){
ste=st[i];
st[i]=st[j];
st[j]=ste;
}
}
}
for (i=0;i<m;i++)
cout <<st[i].s<<endl;
return 0;
}