All 5-letter words composed of the letters A, O, and U are written in alphabetical order. Here is the beginning of the list:

  1. AAAAA
  2. AAAAO
  3. AAAAU
  4. AAAOA ……

Write down the word that is on the 240th place from the beginning of the list.

  • I hardly remember computer science, but you have a simple conversion to the ternary number system 240 .... py.sy. Answer: YYYYA - Vladimir Klykov
  • No, the answer is YYYOA, since the countdown must be started from scratch, and not from one. - gammaker

1 answer 1

Something like this:

char str[6]={0}; char chars[3]={'A', 'O', 'Y'}; //Для перевода троичных цифр в буквы int a; cin >> a; a--; //В коде отсчёт идёт с нуля, а не с единицы, как по условию задачи //Переводим в троичную систему делением на 3 и записыванием остатка в обратном порядке for(int pos=4; pos>=0; pos--) { str[pos]=chars[a%3]; a/=3; } cout << str; 
  • And detail? - Koshiar
  • Added comments to the code. - gammaker