poao899 1249 Accepted 784K 182MS G++ 1.47K 2010-04-06 01:41:49 .
糟糕co好長
猥是猥瑣了些但不難
//**********************
#include<algorithm>
struct str{
char s[70];
bool operator<(const str &b)const{
for(int i=0; i<70; i++){
if(s[i]> b.s[i])return 0;
else if(s[i]< b.s[i])return 1;
}
return 0;
}
void get(){
gets(s);
int i=0;
for(; s[i]&&s[i]!=32; ++i);
for(; i<70; ++i)
s[i]= 0;
}
};
struct name{
str pre, now;
void get(){
pre.get(); now=pre;
std::sort(now.s, now.s+strlen(now.s));
}
bool operator<(const name &b)const{
return now<b.now || !(now<b.now)&&!(b.now<now)&&pre<b.pre;
}
}na[7000], t;
struct out{
str ord;
int st, ed;
bool operator<(const out &b)const{
return ord< b.ord;
}
}o[7000];
int n, oCnt;
bool can;
char buf[70];
void push(str ord, int st, int ed){
o[oCnt].ord= ord;
o[oCnt].st= st;
o[oCnt].ed= ed;
++oCnt;
}
int main(){
while(gets(buf)){
sscanf(buf, "%d", &n);
if(n==0)break;
oCnt= 0;
for(int i=0; i<n; ++i)
na[i].get();
std::sort(na, na+n);;
for(int i=0, j; i<n; ++i){
t= na[i];
for(j=i; j<n; ++j){
if(t.now< na[j].now)break;
}
if(j>i+1){
push(na[i].pre, i, j);
i= j-1;
}
}
if(!oCnt)puts("No Answer");
else{
std::sort(o, o+oCnt);
for(int i=0; i<oCnt; i++){
for(int j=o[i].st; j<o[i].ed; ++j){
if(j!=o[i].st)printf(",");
printf("%s", na[j].pre.s);
}
puts("");
}
}
}
}
沒有留言:
張貼留言