| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
受不了了!!我是用二维数组做的,各种例子都过了怎么老说是wrong answer?大牛哥大牛姐们帮我看看吧..拜托了!!#include<iostream>
using namespace std;
int main()
{
char a[110][60],b[110];
int i,j,x,m,n,s,q,r;
cin>>n>>m;
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>a[i][j];
for(i=0;i<m;i++)//求出各行中的逆序数数目
{
int t=0;
for(j=0;j<n-1;j++)
{
for(x=1;x<n-j;x++)
if(a[i][j]>a[i][j+x]) t++;
}
b[i]=t;
}
for(s=0;s<=m;s++)//用冒泡法根据逆序数数目大小按行将数组排序
{
for(i=0;i<m-1;i++)
if(b[i]>b[i+1])
{
q=b[i];b[i]=b[i+1];b[i+1]=q;
for(j=0;j<n;j++)
{r=a[i][j];a[i][j]=a[i+1][j];a[i+1][j]=r;}
}
}
for(i=0;i<m;i++)
{for(j=0;j<n;j++)
cout<<a[i][j];
cout<<endl;}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator