日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c语言编程时碰到取整去不了_碰到编程墙时如何解开

發(fā)布時間:2023/11/29 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言编程时碰到取整去不了_碰到编程墙时如何解开 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

c語言編程時碰到取整去不了

Getting stuck is part of being a programmer, no matter the level. The so-called “easy” problem is actually pretty hard. You’re not exactly sure how to move forward. What you thought would work doesn’t.

無論身在何處,陷入困境都是成為程序員的一部分。 所謂的“簡單”問題實(shí)際上很難解決。 您不確定如何前進(jìn)。 您認(rèn)為可行的方法無效。

The other part of being a programmer is getting yourself unstuck.

成為程序員的另一部分是讓自己陷入困境。

I’ve been getting stuck a lot recently, so finding ways to get unstuck has been ever-present on my mind. Here are a few tactics I’ve been using. Maybe they can help you, too.

我最近一直被困住,所以一直想著找到解困的方法。 這是我一直在使用的一些戰(zhàn)術(shù)。 也許他們也可以幫助您。

使問題具體化 (Make the problem concrete )

Create a diagram, make a quick sketch, or use actual objects to give yourself a visual. It’ll make the problem a lot easier to think about.

創(chuàng)建圖表,快速繪制草圖,或使用實(shí)際對象為自己提供視覺效果。 這將使問題更容易思考。

One problem I faced asked me to find the absolute difference between the sums of a square matrix’s diagonals. That’s a mouthful and a lot to keep in my head. So I drew it out: I created a square matrix of numbers and circled the diagonals. ?

我遇到的一個問題要求我找出方陣對角線之和之間的絕對差。 那真是令人mouth目結(jié)舌,還有很多事需要我注意。 因此,我將其繪制出來:我創(chuàng)建了一個由數(shù)字組成的方陣,并圈出對角線。

A simple sketch literally made the steps jump out at me: sum one diagonal (which is 15), then the other (which is 17), and then find the absolute difference between them (which is 2).

一個簡單的草圖從字面上使我跳了一步:將一個對角線(為15)求和,然后將另一個對角線(為17)求和,然后找出它們之間的絕對差(為2)。

This approach applies to other problems, too. When I was learning about for loops, I iterated through a pile of almonds. When I’m working on a recursive problem, I’ll make a diagram to see what’s happening on the call stack until I hit my base case.

這種方法也適用于其他問題。 當(dāng)我學(xué)習(xí)循環(huán)時,我遍歷了一堆杏仁。 當(dāng)我處理遞歸問題時,我將制作一個圖表,以查看調(diào)用堆棧上正在發(fā)生的事情,直到找到基本情況為止。

The commonality is this: make the abstract concrete.

共同點(diǎn)是這樣的:將抽象具體化。

準(zhǔn)確寫下您要做什么 (Write out exactly what you’re trying to do)

Write down the specific step you’re working on when you feel the all-too-familiar “spinning your wheels” cycle come upon you. ?

當(dāng)您感覺到非常熟悉的“旋轉(zhuǎn)輪子”周期來到時,寫下您正在執(zhí)行的特定步驟。

The five or ten seconds it takes to jot down a few words on a piece of paper will help you solidify your thought process and redirect your attention.

在一張紙上寫下幾句話需要五到十秒鐘,這將幫助您鞏固思考過程并轉(zhuǎn)移注意力。

Here are some examples:

這里有些例子:

  • Store the course names as keys in the object

    將課程名稱存儲為對象中的鍵
  • Pass the argument to the callback function

    將參數(shù)傳遞給回調(diào)函數(shù)
  • Reset the “maxValue” variable to 0

    將“ maxValue”變量重置為0

Resetting the “maxValue” variable, for example, didn’t solve the problem. But it was an important step in the process. Writing this short phrase got me back on track: it was a reminder of what I’d set out to do. It also ensured I was focused on one thing, not many.

例如,重設(shè)“ maxValue”變量并不能解決問題。 但這是該過程中的重要一步。 寫這個簡短的短語讓我回到了正軌:這提醒了我要去做的事情。 這也確保我專注于一件事,而不是很多。

So the next time you find yourself trying the same approach over and over again and getting the same result, stop yourself and ask: “What exactly am I trying to do here?”

因此,下次您發(fā)現(xiàn)自己一次又一次地嘗試相同的方法并獲得相同的結(jié)果時,停下來問自己:“我在這里到底想做什么?”

Then, write—yes, write—your answer down on a piece of paper.

然后,在一張紙上寫下(是,寫下)您的答案。

It’s not enough to think of your response. If I casually “think” to myself, I’ll rush the process and not much (if anything) is gained. I’ve got to write it down.

僅僅考慮您的回應(yīng)是不夠的。 如果我隨便對自己“思考”,我會匆忙完成該過程,但不會獲得太多(如果有的話)。 我必須把它寫下來。

簡化您的給定輸入 (Simplify your given input)

It’s far less intimidating to work with a few things than many. That's why it's helpful to simplify your given input.

處理幾件事情比許多事情少得多。 這就是為什么簡化給定輸入會有所幫助的原因。

One problem gave me a list of three dictionaries. It was only three dictionaries, but that was still two too many.

一個問題給我列出了三本詞典。 只有三本字典,但那仍然是兩本太多。

names = [{'first':'John', 'last':'Smith', 'email':'johns@example.com'},{'first':'Mary', 'last':'McDonald', 'email':'marym@example.com'},{'first':'Sam', 'last':'Davey', 'email':'samd@example.com'} ]

My job was to sort each dictionary by last name, then by first name (ie, Davey, Sam: samd@example.com). However, the problem was easier to think about when I made the list of three dictionaries a list of one. ?

我的工作是按姓氏,然后按名字(即Davey,Sam:samd@example.com)對每本詞典進(jìn)行排序。 然而, 當(dāng)我將三本詞典的列表設(shè)為一本的列表時,這個問題更容易思考。

name = [{'first':'John', 'last':'Smith', 'email':'johns@example.com'} ]

I solved the problem using a single dictionary. Then, I applied the same logic to the larger problem at hand.

我用一個字典解決了這個問題。 然后,我對即將出現(xiàn)的較大問題應(yīng)用了相同的邏輯。

When you simplify your given input, you make the problem much more manageable.

當(dāng)您簡化給定的輸入時,將使問題更易于管理。

解決一個較小的問題 (Solve a smaller problem)

Spot patterns more easily and understand what you're really asked to do when you solve a smaller version of the problem.

更輕松地找出模式并了解解決較小版本問題時的真正要求。

Here’s an example problem from Reuven Lerner’s book, Python Workout:

這是Reuven Lerner的書Python Workout中的一個示例問題:

“Use a list comprehension to reverse the word order of lines in a text file. That is, if the first line is abc def and the second line is ghi jkl, then you should return the list ['def abc', 'jkl ghi'].”

“使用列表推導(dǎo)來反轉(zhuǎn)文本文件中各行的單詞順序。 也就是說,如果第一行是abc def,第二行是ghi jkl,則應(yīng)該返回列表['def abc','jkl ghi']。”

When solving a smaller version of a problem, I find it helpful to remove layers of complexity and use my ideal data structure. In this example, that meant ignoring the text file and list comprehension (layers of complexity) and using a list (my ideal data structure).

解決較小版本的問題時,我發(fā)現(xiàn)消除復(fù)雜性層并使用理想的數(shù)據(jù)結(jié)構(gòu)會有所幫助。 在此示例中,這意味著忽略文本文件和列表理解(復(fù)雜性層),而使用列表(我理想的數(shù)據(jù)結(jié)構(gòu))。

Then I solved the problem. I opened up my editor and typed out my ideal data structure.

然后我解決了問題。 我打開編輯器,輸入理想的數(shù)據(jù)結(jié)構(gòu)。

letters = ['abc def', 'ghi jkl']

I reversed the order and got the expected result using a for loop.

我顛倒了順序,并使用for循環(huán)獲得了預(yù)期的結(jié)果。

reversed_letters = [] for letter in letters:letter_list = letter.split(" ")letter_list.reverse()reversed_letters.append(" ".join(letter_list))

Once I got that working, I added the layers of complexity back in one at a time until I solved the problem as the problem statement asked.

一旦工作完成,我就一次又一次添加了復(fù)雜性,直到按照問題陳述的要求解決了問題。

Solving a smaller version of the problem helps get you to the heart of what you need to do. It's also another way to make the complex simple.

解決問題的較小版本有助于您深入了解所需要做的事情。 這也是使復(fù)雜結(jié)構(gòu)簡單的另一種方法。

休息一下 (Take a break )

Your brain doesn’t stop thinking just because your fingers stop typing.

您的大腦不會因?yàn)槭种竿V勾蜃侄V顾伎肌?

Has an idea ever “popped” into your head while you were doing something other than programming? Have you ever returned to a problem after a workout and the solution is staring you in the face? It’s happened to me.

當(dāng)您進(jìn)行編程以外的工作時,有沒有一個主意“突然出現(xiàn)”? 運(yùn)動后,您是否曾經(jīng)遇到過問題,而解決方案卻使您目不轉(zhuǎn)睛? 這是發(fā)生在我身上。

It’s no coincidence that you arrived at your idea or solution when you were doing something else—when you weren’t deliberately working. “Epiphanies may seem to come out of nowhere,” explains Scientific American, “but they are often the product of unconscious mental activity during downtime.”

當(dāng)您在做其他事情時(不是在刻意工作的時候)得出您的想法或解決方案,這并非巧合。 《 科學(xué)人雜志 》解釋說:“突然顯現(xiàn)似乎無處不在,但它們通常是停機(jī)期間無意識的精神活動的產(chǎn)物。”

If you feel like you’re running up against a brick wall, you very well could be. It may be best to take a break. Give your mind some time to digest what you’re working on and return to the problem renewed.

如果您感覺自己撞上了磚墻,那很可能是這樣。 最好休息一下。 給您一些時間來消化您正在做的事情,然后重新解決問題。

與其他程序員配對 (Pair with another programmer)

Working with someone else can be a great way to generate ideas and see a problem from another perspective. But I highly recommend you do everything in your power to get yourself unstuck first.

與他人合作可能是產(chǎn)生想法并從另一個角度看問題的好方法。 但我強(qiáng)烈建議您盡一切可能先將自己粘在身上。

There will always be roadblocks. Learning how to troubleshoot your own problems is a critical skill to learn. It’s easy to say “I don’t get it. Let me ask this senior engineer.” Then, have the senior engineer solve the problem for you. It’s harder to figure it out yourself, but you need to at least try.

總會有障礙。 學(xué)習(xí)如何解決自己的問題是學(xué)習(xí)的一項(xiàng)關(guān)鍵技能。 容易說“我不明白。 讓我問這個高級工程師。” 然后,請高級工程師為您解決問題。 自己弄清楚很難,但至少需要嘗試一下。

If you’ve sincerely put your best foot forward, then reach out to a programmer with a specific question. This shows respect for the other programmer’s time and it’ll make your pairing session more effective.

如果您真誠地提出了自己最好的建議,那么請向程序員咨詢特定的問題。 這表示尊重其他程序員的時間,這將使您的配對會話更加有效。

Then, ask for a hint—don’t have the programmer solve the problem for you. You’ll undoubtedly encounter a similar situation down the road, so use the pairing session as a learning opportunity. It’ll help you in the long run.

然后,尋求提示-不要讓程序員為您解決問題。 毫無疑問,您將來會遇到類似的情況,因此請使用配對課程作為學(xué)習(xí)機(jī)會。 從長遠(yuǎn)來看,它將為您提供幫助。

結(jié)語 (Wrapping up)

Getting stuck is frustrating, to be sure. You may try just one of the above tactics and have a “l(fā)ight bulb” moment, or you may need to try a combination and find yourself simply inching along during the process.

當(dāng)然,卡住令人沮喪。 您可能只嘗試了上述一種策略,并有一個“燈泡”時刻,或者您可能需要嘗試一種組合,并發(fā)現(xiàn)自己在此過程中只是微不足道。

But there are two things I’ve learned from embracing the struggle: I’m learning a lot and the breakthrough is coming. Keep at it.

但是,從這場斗爭中我學(xué)到了兩件事:我學(xué)到了很多東西,并且突破即將來臨。 繼續(xù)吧

I write about learning to program, and the best ways to go about it (amymhaddad.com).

我寫了有關(guān)學(xué)習(xí)編程的文章,以及進(jìn)行編程的最佳方法 ( amymhaddad.com )。

翻譯自: https://www.freecodecamp.org/news/how-to-get-unstuck/

c語言編程時碰到取整去不了

總結(jié)

以上是生活随笔為你收集整理的c语言编程时碰到取整去不了_碰到编程墙时如何解开的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。