200-rare Order
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=136
For a list of words, these words are arranged in an unknown dictionary order, which requires the order of the letters to be printed.
Idea: It's obvious that the topology sort.
Note that the last to output more than one line, otherwise it will wa!
Complete code:
/*0.016s*/#include <bits/stdc++.h> using namespace std;
List<int> l[27];
Char last[25], now[25];
BOOL has[27], vis[27];
int ans[27], CNT;
void Dfs (int i) {vis[i] = true; if (L[i].size ()) for (List<int>::iterator iter = L[i].begin (); Iter!= l[i].end (); ++iter) if (!
Vis[*iter]) DFS (*iter);
ans[cnt++] = i;
int main () {int Len, I;
Gets (last);
HAS[LAST[0] &) = true;
while (gets), now[0]!= ' # ' is {len = min (strlen (last), strlen (now)); for (i = 0; i < len; ++i) {if (Last[i]!= now[i]) {Has[last[i] &
= Has[now[i] & = true;
L[last[i] & 31].push_back (Now[i] & 31);
Break
} memcpy (last, now, sizeof (now));
for (i = 1; i < ++i) if (Has[i] &&!vis[i]) DFS (i); for (i = cnt-1 i >= 0; i.) Putchar (Ans[i] + ' A '-1);
Putchar (10);///tried to add a new line, AC, I was too young ...
return 0; }
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/