fork download
  1. #include <iostream>
  2. #include <queue>
  3. using namespace std;
  4.  
  5. int main ()
  6. {
  7. int n;
  8. string total = "";
  9. cin>>n;
  10. for (int i=1; i<=n; i++)
  11. {
  12. string tmp;
  13. cin>>tmp;
  14. total+=(tmp + " ");
  15. }
  16. /*input:
  17.   3
  18.   a
  19.   bv
  20.   gva
  21.   -> total = "a bv gva"
  22.   */
  23. string base = "abcdefghijklmnopqrstuvwxyz";
  24. string u = "";
  25. queue <string> q;
  26. q.push(u);
  27. while (!q.empty())
  28. {
  29. string f = q.front();
  30. q.pop();
  31. for (int i=0; i<base.length(); i++)
  32. {
  33. string v = f+base[i]; //each v we have: a, b, c ..., z, aa, ab, ..., zz, ... aaa, ...
  34. q.push(v);
  35. if (total.find(v)==-1)
  36. {
  37. cout<<v;
  38. return 0;
  39. }
  40. }
  41. }
  42. return 0;
  43. }
Success #stdin #stdout 0s 4360KB
stdin
6
aa
bcdefg
hijklm
nopqrs
tuvwxy
z
stdout
ab