为什么这里过不了,,,
using namespace std; int l,num; char s[20]; bool v[20]; char map[20]; bool flag = false; int cnt = 0; bool isvol(char c){ return c == ‘a’ || c == ‘e’ || c == ‘i’ || c == ‘o’ || c == ‘u’; } bool check(char s[]){ int cntv = 0,cntu = 0; for(int i = 0;i < l;i ++){ if(isvol(s[i]))cntv ++; else cntu ++; //if(i > 0 && s[i] < s[i-1])return false; } return cntv >= 1 && cntu >= 2; } //bool cmp(char a[],char b[]){ // return a[0] < b[0]; //} void dfs(int i,int k){ //cout<<”i = “<<i<<” k = “<<k<<endl; if(k == l){ s[k] = ‘\0’; if(check(s)){ printf(“%s\n”,s); cnt ++; if(cnt == 25000)flag = true; } return ; } for(i;i < num && !flag;i ++){ if(!v[i]){ v[i] = true; s[k] = map[i]; dfs(i,k + 1); v[i] = false; } } return ; } int main(){ while(scanf(“%d%d”,&l,&num) != EOF){ char c[3]; memset(v,false,sizeof(v)); cnt = 0; flag = false; for(int i = 0;i < num;i ++){ scanf(“%s”,c); map[i] = c[0]; } sort(map,map+num); dfs(0,0); } return 0; }
为什么这里过不了,,,
include
include
include
include
using namespace std;
int l,num;
char s[20];
bool v[20];
char map[20];
bool flag = false;
int cnt = 0;
bool isvol(char c){
return c == ‘a’ || c == ‘e’ || c == ‘i’ || c == ‘o’ || c == ‘u’;
}
bool check(char s[]){
int cntv = 0,cntu = 0;
for(int i = 0;i < l;i ++){
if(isvol(s[i]))cntv ++;
else cntu ++;
//if(i > 0 && s[i] < s[i-1])return false;
}
return cntv >= 1 && cntu >= 2;
}
//bool cmp(char a[],char b[]){
// return a[0] < b[0];
//}
void dfs(int i,int k){
//cout<<”i = “<<i<<” k = “<<k<<endl;
if(k == l){
s[k] = ‘\0’;
if(check(s)){
printf(“%s\n”,s);
cnt ++;
if(cnt == 25000)flag = true;
}
return ;
}
for(i;i < num && !flag;i ++){
if(!v[i]){
v[i] = true;
s[k] = map[i];
dfs(i,k + 1);
v[i] = false;
}
}
return ;
}
int main(){
while(scanf(“%d%d”,&l,&num) != EOF){
char c[3];
memset(v,false,sizeof(v));
cnt = 0;
flag = false;
for(int i = 0;i < num;i ++){
scanf(“%s”,c);
map[i] = c[0];
}
sort(map,map+num);
dfs(0,0);
}
return 0;
}