错了3和4 代码如下
#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
int n,m,b,sb;
short num[25][105];//string转num
struct elector{
short no;//序号
string v;//vote
short len;//vote的长度
}e[25];
void numin(int a){
for(int i=1;i<=sb;i++)
num[a][i]=e[a].v[i-1]-'0';
}
void numswap(int i){
int c=i+1;
for(int j=1;j<=sb;j++)
if(num[i][j]<num[c][j]){
swap(e[i],e[c]);
}
}
bool cddx(elector a,elector b){
return a.len>b.len;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=0;i<n;i++){
e[i].no=i+1;
cin>>e[i].v;
e[i].len=e[i].v.length();
}
sort(e,e+n,cddx);
sb=e[0].len;
b++;
for(int i=0;;i++){
if(e[i].len!=sb)
break;
b++;
}
for(int i=0;i<b-1;i++){
numin(i);
for(int j=1;j<=sb;j++)
cout<<num[i][j];
cout<<endl;
}
for(int k=0;k<n;k++)
for(int i=0;i<b-1;i++)
numswap(i);
cout<<e[0].no<<endl<<e[0].v;
return 0;
}
注:在我的调试中发现是numswap函数出了问题:始终不会触发
numswap为冒泡排序法