-
Notifications
You must be signed in to change notification settings - Fork 0
6. Zigzag Conversion #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #if __has_include("../debug.hpp") | ||
| #include "../debug.hpp" | ||
| #endif | ||
| // ここまでローカルでのデバッグ用なので気にしないでください -------------------- | ||
|
|
||
| #include <bits/stdc++.h> | ||
|
|
||
| using namespace std; | ||
|
|
||
| // <時間> | ||
| // 8分 | ||
| // <疑問・不安点(・個人的な感想、違う意見があれば教えてほしいもの)> | ||
| // 1.2の方に書く | ||
|
|
||
| // なお以下で出てくるコメントはプロダクト版にも書くつもりのコメント | ||
| class Solution { | ||
| public: | ||
| string convert(string s, int numRows) { | ||
| if (numRows == 1) return s; | ||
|
|
||
| vector<string> rows(numRows); | ||
| int direction = 1, row = 0; | ||
| for (int i = 0; i < s.size(); ++i) { | ||
| rows[row] += s[i]; | ||
| if (direction == 1) { | ||
| if (row == numRows - 1) { | ||
| direction = -1; | ||
| } | ||
| } else { | ||
| if (row == 0) { | ||
| direction = 1; | ||
| } | ||
| } | ||
| row += direction; | ||
| } | ||
| return reduce(rows.begin(), rows.end()); | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #if __has_include("../debug.hpp") | ||
| #include "../debug.hpp" | ||
| #endif | ||
| // ここまでローカルでのデバッグ用なので気にしないでください -------------------- | ||
|
|
||
| #include <bits/stdc++.h> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C++に詳しくないんですが, Macでコンパイル使用しようとしたらnot foundと出たので環境依存なものだったりするんでしょうか, production codeではどういう扱いなんでしょうか, 少し調べてみたところ<bits/stdc++.h>はいろんなファイルをincludeしていてコンパイル時間と実行ファイルの重さが増える気がしました。
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. レビューありがとうございます! |
||
|
|
||
| using namespace std; | ||
|
Comment on lines
+6
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 練習では include は真面目に書いたほうがいいと思います。 コードを書くのは知的な行為ではないので、できるかできないかではなくてするかしないかだと思っています。 using namespace std; は、使うこともあるのでまだいいんですが、.h でやると悲惨なことになります。そういう意味で必ずできるものではないが、.h を練習で書くことはなさそうなので、大半のコードはこれなしで書いたほうがいいように思いますね。
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C++割と得意なんで許してください…、では駄目ですか?笑 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 自己評価が高すぎるように感じます。謙虚になられることをおすすめいたします。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. いや、まあ、好きにすればいいんですが、逆の話として、小西さんは6時間かからずに60問書き上げた、といっています。そうならば、そもそもこの練習をする必要はないです。 寿司職人として寿司の握り方を覚える際に、髪の毛触っていてもいいですか、と同じ話だと思っています。
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. すみません。
僕もgitのコマンドをエイリアスでたたくかフルで叩くかの違いだとは思っていますが、何か新しい発見があるかもしれませんし、Mac環境の人がレビューしずらいと思いますので、これからはちゃんとincludeしたいと思いますmm There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ここからは私の解釈ですが、自分の悪いところを認めて、相手に誤解を認めさせて、あいこにして解決するというコミュニケーションを取ってきていて、それで報酬系が回っているので、そのパターンにしようとしたのではないかと推測しています。 『決してC++出来る自慢ではない』という発言が出てきたのも、噛み合っていない印象を持っています。私が話していたのは「調べる動作がされていない」というのは「自慢や自己評価が高いことは驕っているので悪い」ということではないです。人間としての性格の問題ではなくて、専門家の取る基本的な行動をしているかについての話です。なので、これも突然自分の性格の話にすり替えられたように感じます。 ここで伝えたかったことは、だいたいこれくらい噛み合っていないと思っているので、なにか書き始める前に、なにが書かれているのかをこれくらい分析する習慣をつけたほうがいいということです。
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
なるほどです。すみません、これは僕がちゃんと小田さんの説明(正確には僕の説明を小田さんが信じたこと)を信じ切れていなかったのが原因でした。
これもよく分かっていませんでした。
すみません、これは意図的です。この話は僕にとっては反感を買うことを言ってしまったから、相手がそうなった理由を考えて、そうではないと伝えることが大事だと思っていましたので。
そういう訳ではありません。僕は僕目線から(僕自身は客観的になり得ないのでこの言い方になります)間違っていることはそう伝え、自分が間違っているところは認めています。
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (以下、一般の人と違う僕の考え(真意)を少し書いておきます。ただ単に僕の真意を伝える目的であって、伝わる(共感が得られる)話かは自分で怪しいと思っているので…、伝わらなかったら無視してもらって大丈夫です。ちょっとこれを話すのは小田さんが「追加しないでおくつもりだった」とおっしゃったように僕も過度かなと思ったのですが、同じような話がこれから先も起こらないとは限らない(努力はします…)ので一応書いてみます。
①会話において論理はあまり関係ないこと。(もちろんCSにおける議論では論理は最重要視しています。ですがそれ以外ではそうとは限りません。僕の勘違いでしたが、この話もそうだと思っていたので、冗談の話をするアプローチ(感情)の選択を取りました) ②会話は誰が喋るかによって、その結果はいかようにも変わること。つまり相手のことを理解していない状態ではうまく行く話もうまく行かないということです。これは文章による会話には限界があると僕が思っているという話で、僕自身の印象も会ってみたら違うものがあると思っているという話です(僕が指摘回避をしているという誤解等について言っています)。
マインドセットとは、「ある靴を履かない国に、靴会社の営業マンAとBが派遣されたら、それぞれの上司に、Aは『この国は靴を履かないので、靴は売れません!』と報告し、Bは『靴の良さを宣伝して売れば、市場はがら空きなので大儲けできます!』と報告した」というやつです。経験や性格によって形成さる考え方の「癖」のことです。 まあ要は、人間はどうやっても客観視は出来ないという話で、それが「アリストテレスのエトス>パトス>ロゴス理論」の補強にもなっていますし(どんなに論理的な話であれエトスやパトスが説得力を左右する)、先ほどまで、僕にとっては、小田さんの話の中身より、小田さんが僕の話を信じてくれたかの方が僕にとっては大事だったという話です(疑ってすみません)。これを僕が言うのは正当化しているように聞こえるかもしれませんが、「伝わった上でおっしゃっているなら納得です。」という話になるのはそういうことです) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
これは冗談でも自慢でも、あまりプロフェッショナルとしての評価は変わりがないでしょう。 私も一番の問題点をここまで掴みそこねていた気がするのですが、関係のない話をして「コメントを故意に無視した」ことが一番の問題です。レビューの場においてエンジニアリングの目的に繋がってしているコメントなのだから、なんらかのエンジニアリングの目的に繋がる反応が求められます。「自分がどのような分類であるか」はエンジニアリングの目的に関係がなく、それ以外には従う気がないくらいしか内容がありません。(だから、「冗談はさておき、〜〜でしょうか。」などがついていたら、だいぶましです。)これくらい目的に繋がらない行動は面接だと一発レッドカードでると思いますね。 仕事のかなりの部分がコミュニケーションコストなので、「コミュニケーションコストを無駄に発生させる」と思われることもマイナスです。実際に仕事の場でこれをやると、後回しや放置をされることも少なくないでしょう。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ただ、この危機感が伝わっている気があまりしません。 自分の行動や考えがエンジニアリングの目的に関係しているかを常に内省し、「受け取る人の立場に立つのがエンジニアリングの本質」ということを強く意識し、これから外れたらイエローカードからレッドカードと理解する、くらいしかアドバイスを思いつかないので、気長に考えてください。 |
||
|
|
||
| // <時間> | ||
| // 8分 | ||
| // <疑問・不安点(・個人的な感想、違う意見があれば教えてほしいもの)> | ||
| // - 他の人のを見ていて1.1の25行目のif文が要らないことに気づいたので | ||
| // それを消したもの。 | ||
| // - 言われた通り、ジグザグに並べた。先頭から順に追加すべきインデックスを | ||
| // 計算することも考えたが素直に書いた方が可読性は良いだろうと考えこうした。 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. はい。素直に書いたほうがいいと思いますね。 |
||
| // - 前にそうやってこの問題を解いたことがあり、SolutionOldのところに | ||
| // その回答を載せた。一応この方が速度は速い。 | ||
| // - row == numRows - 1かrow >= numRows - 1か | ||
| // - 細かい話だが28行目を空けるか否か | ||
| // (自分はフェーズを分ける意味で改行を使いがち) | ||
|
|
||
| // なお以下で出てくるコメントはプロダクト版にも書くつもりのコメント | ||
| class Solution { | ||
| public: | ||
| string convert(string s, int numRows) { | ||
| if (numRows == 1) return s; | ||
|
|
||
| vector<string> rows(numRows); | ||
| int direction = 1, row = 0; | ||
| for (int i = 0; i < s.size(); ++i) { | ||
| rows[row] += s[i]; | ||
| if (row == numRows - 1) { | ||
| direction = -1; | ||
| } else if (row == 0) { | ||
| direction = 1; | ||
| } | ||
| row += direction; | ||
| } | ||
| return reduce(rows.begin(), rows.end()); | ||
| } | ||
| }; | ||
|
|
||
| class SolutionOld { | ||
| public: | ||
| string convert(string s, int numRows) { | ||
| if (numRows == 1) return s; | ||
| string retval; | ||
| for (int row = 0; row < numRows; ++row) { | ||
| for (int i = row; i - row * 2 < static_cast<int>(s.size()); | ||
| i += numRows * 2 - 2) { | ||
| if (row > 0 && row < numRows - 1) { | ||
| if (i - row * 2 > 0) retval += s[i - row * 2]; | ||
| } | ||
| if (i < s.size()) retval += s[i]; | ||
| } | ||
|
Comment on lines
+50
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ここ、もうちょっと読みやすくできないですかね。 for (int offset = 0; offset < s.size() + row; offset += numRows * 2 - 2) {
if (0 < row && row < numRows - 1 && 0 < offset - row) {
retval += s[offset - row];
}
if (offset + row < s.size()) {
retval += s[offset + row];
}
}
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. すみません、ありがとうございます。 |
||
| } | ||
| return retval; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. retvalよりも良い名前を考えてみるといいかもです。discordで他の人のコードを読んでみるのがおすすめです There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. あ、すみませんこれは前書いたコードだったんですね |
||
| } | ||
| }; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
row の値を i と numRows に関する計算式で求めることはできますか? direction を足していく方法とどちらがシンプルですか?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
やってみます!
少々お待ちください…