Skip to content

127. Word Ladder#19

Open
hemispherium wants to merge 1 commit into
mainfrom
127-word-ladder
Open

127. Word Ladder#19
hemispherium wants to merge 1 commit into
mainfrom
127-word-ladder

Conversation

@hemispherium
Copy link
Copy Markdown
Owner

@hemispherium hemispherium self-assigned this Apr 10, 2026
Comment thread 127-word-ladder/step1.cpp
return 0;
}

queue<pair<string, int>> q;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q はキューを表しているのでしょうか。

変数を型名にしても、読み手にとって得られる情報はあまりないように思いました。変数名には、どのような値が格納されているかが分かる名前を付けると、より読みやすくなると思います。

また、個人的には、コンテナの変数名は、複数形を表す s で終えるようにしています。 word_and_lengths や word_and_steps はいかがでしょうか?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そうですね、word_and_lengths や word_and_stepsの方がよさそうです。

Comment thread 127-word-ladder/step1.cpp
}

queue<pair<string, int>> q;
q.push({ beginWord, 1 });
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::queue::emplace() を使用すると、要素の型のコンストラクターの引数を直接指定して、要素を追加することができます。
https://cpprefjp.github.io/reference/queue/queue/emplace.html

q.emplace(beginWord, 1);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そうですね、emplaceの方がすっきり書けてよさそうです。

Comment thread 127-word-ladder/step2.cpp
return 0;
}

queue<pair<string, int>> wordToCount;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To は、 map や unordered_map の場合に使う印象があります。また、 wordToCount だと、単語の出現回数というニュアンスを感じます。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants