| ||||||||||
| 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 | |||||||||
poj的编译器要更新了。。。类名和一个字段重名都能报错,苯地跑的好不过的#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
struct Word{
char word[10];
int len;
int wordcnt[26];
}dict[110];
bool compare(const Word &w1, const Word &w2){
return strcmp(w1.word, w2.word) < 0;
}
int main() {
int cnt = 0;
while(1){
scanf("%s", dict[cnt].word);
if(dict[cnt].word[0] == 'X') break;
dict[cnt].len = strlen(dict[cnt].word);
for(int i = 0; i < 26; i++) dict[cnt].wordcnt[i] = 0;
for(int i = 0; i < dict[cnt].len; i++){
dict[cnt].wordcnt[dict[cnt].word[i]-'a'] ++;
}
cnt++;
}
sort(dict, dict+cnt, compare);
char word[10];
while(1){
scanf("%s", word);
if(word[0] == 'X') break;
bool ky = 0;
int len = strlen(word);
int wordcnt[26] = {0};
for(int i = 0; i < len; i++){
wordcnt[word[i]-'a']++;
}
for(int i = 0; i < cnt; i++){
if(dict[i].len != len) continue;
bool shide = 1;
for(int j = 0; j < 26; j++){
if(wordcnt[j] != dict[i].wordcnt[j]){
shide = 0;
break;
}
}
if(shide){
ky = 1;
printf("%s\n", dict[i].word);
}
}
if(!ky){
printf("NOT A VALID WORD\n");
}
printf("******\n");
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator