len=0 break
len=1,f=0,ans++,保留前一行的v数组,即len不变;f=1,重新确定下一列中需要判哪一行(标记法),跟新v数组
这题思路很清晰,但是写代码的时候弄错好几个变量,列和行写反,实际上要注意不能想当然的写变量!
代码:
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
using namespace std;
#define maxn 200
char s[maxn][maxn];
int ans;
vector<int>v;
int main(){
ans=;
int n,m;
cin>>n;
rep(i,,n){
scanf("%s",s[i]);
}
m=strlen(s[]);
rep(i,,n){
v.push_back(i);
}
int col=;
while(col<m){
bool f=;
int len=v.size();
//cout<<len<<endl;
if(len==){
break;
}
rep(i,,len){
char x=s[v[i]][col];
char y=s[v[i-]][col];
if(x<y)
{
f=;
//cout<<x<<" "<<y<<endl;
break;
}
}
if(f){
int tmp[maxn];
rep(i,,len){
char x=s[v[i]][col];
char y=s[v[i-]][col];
if(x==y){
tmp[v[i]]=;
tmp[v[i-]]=;
}
}
v.clear();
rep(i,,n){
if(tmp[i])
v.push_back(i);
}
}
else ans++;
col++; }
cout<<ans<<endl;
return ;
}