c語言編程時碰到取整去不了_碰到編程墻時如何解開

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.

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

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.

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

使問題具體化 (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.

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

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目結舌,還有很多事需要我注意。 因此,我將其繪制出來:我創建了一個由數字組成的方陣,并圈出對角線。

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.

這種方法也適用于其他問題。 當我學習循環時,我遍歷了一堆杏仁。 當我處理遞歸問題時,我將制作一個圖表,以查看調用堆棧上正在發生的事情,直到找到基本情況為止。

The commonality is this: make the abstract concrete.

共同點是這樣的:將抽象具體化。

準確寫下您要做什么 (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. ?

當您感覺到非常熟悉的“旋轉輪子”周期來到時,寫下您正在執行的特定步驟。

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.

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

Here are some examples:

這里有些例子:

  • Store the course names as keys in the object

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

    將參數傳遞給回調函數
  • 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.

例如,重設“ 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?”

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

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.

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

簡化您的給定輸入 (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)對每本詞典進行排序。 然而, 當我將三本詞典的列表設為一本的列表時,這個問題更容易思考。

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.

我用一個字典解決了這個問題。 然后,我對即將出現的較大問題應用了相同的邏輯。

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

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

解決一個較小的問題 (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'].”

“使用列表推導來反轉文本文件中各行的單詞順序。 也就是說,如果第一行是abc def,第二行是ghi jkl,則應該返回列表['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).

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

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

然后我解決了問題。 我打開編輯器,輸入理想的數據結構。

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

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

我顛倒了順序,并使用for循環獲得了預期的結果。

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.

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

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.

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

休息一下 (Take a break )

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

您的大腦不會因為手指停止打字而停止思考。

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.

當您進行編程以外的工作時,有沒有一個主意“突然出現”? 運動后,您是否曾經遇到過問題,而解決方案卻使您目不轉睛? 這是發生在我身上。

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.”

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

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.

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

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.

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

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.

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

結語 (Wrapping up)

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

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

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.

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

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

我寫了有關學習編程的文章,以及進行編程的最佳方法 ( amymhaddad.com )。

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

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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390583.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390583.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390583.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

初創公司怎么做銷售數據分析_為什么您的初創企業需要數據科學來解決這一危機...

初創公司怎么做銷售數據分析The spread of coronavirus is delivering a massive blow to the global economy. The lockdown and work from home restrictions have forced thousands of startups to halt expansion plans, cancel services, and announce layoffs.冠狀病毒的…

leetcode 909. 蛇梯棋

題目 N x N 的棋盤 board 上,按從 1 到 N*N 的數字給方格編號,編號 從左下角開始,每一行交替方向。 例如,一塊 6 x 6 大小的棋盤,編號如下: r 行 c 列的棋盤,按前述方法編號,棋盤格…

Python基礎之window常見操作

一、window的常見操作: cd c:\ #進入C盤d: #從C盤切換到D盤 cd python #進入目錄cd .. #往上走一層目錄dir #查看目錄文件列表cd ../.. #往上上走一層目錄 二、常見的文件后綴名: .txt 記事本文本文件.doc word文件.xls excel文件.ppt PPT文件.exe 可執行…

WPF效果(GIS三維篇)

二維的GIS已經被我玩爛了,緊接著就是三維了,哈哈!先來看看最簡單的效果: 轉載于:https://www.cnblogs.com/OhMonkey/p/8954626.html

css注釋_CSS注釋示例–如何注釋CSS

css注釋Comments are used in CSS to explain a block of code or to make temporary changes during development. The commented code doesn’t execute.CSS中使用注釋來解釋代碼塊或在開發過程中進行臨時更改。 注釋的代碼不執行。 Both single and multi-line comments in…

r軟件時間序列分析論文_高度比較的時間序列分析-一篇論文評論

r軟件時間序列分析論文數據科學 , 機器學習 (Data Science, Machine Learning) In machine learning with time series, using features extracted from series is more powerful than simply treating a time series in a tabular form, with each date/timestamp …

leetcode 168. Excel表列名稱

題目 給你一個整數 columnNumber ,返回它在 Excel 表中相對應的列名稱。 例如: A -> 1 B -> 2 C -> 3 … Z -> 26 AA -> 27 AB -> 28 … 示例 1: 輸入:columnNumber 1 輸出:“A” 示例 2&…

飛機訂票系統

1 #include <stdio.h>2 #include <stdlib.h>3 #include <string.h>4 #include <conio.h>5 typedef struct flightnode{6 char flight_num[10]; //航班號7 char start_time[10]; //起飛時間8 char end_time[10]; //抵達時間9 char st…

解決Mac10.13 Pod報錯 -bash: /usr/local/bin/pod: /System/Library/Frameworks/Ruby.fram

升級10.13以后Pod命令失效&#xff0c;解決辦法如下&#xff1a; 終端執行 brew link --overwrite cocoapods 復制代碼嘗試 Pod 命令是否已經恢復 若報錯繼續執行 brew reinstall cocoapodsbrew install rubybrew link --overwrite cocoapods 復制代碼嘗試 Pod 命令是否已經恢復…

angular示例_用示例解釋Angular動畫

angular示例為什么要使用動畫&#xff1f; (Why use Animations?) Modern web components frequently use animations. Cascading Style-sheets (CSS) arms developers with the tools to create impressive animations. Property transitions, uniquely named animations, mu…

selenium抓取_使用Selenium的網絡抓取電子商務網站

selenium抓取In this article we will go through a web scraping process of an E-Commerce website. I have designed this particular post to be beginner friendly. So, if you have no prior knowledge about web scraping or Selenium you can still follow along.在本文…

劍指 Offer 37. 序列化二叉樹

題目 序列化是將一個數據結構或者對象轉換為連續的比特位的操作&#xff0c;進而可以將轉換后的數據存儲在一個文件或者內存中&#xff0c;同時也可以通過網絡傳輸到另一個計算機環境&#xff0c;采取相反方式重構得到原數據。 請設計一個算法來實現二叉樹的序列化與反序列化…

ie8 ajaxSubmit 上傳文件提示下載

轉載 解決ie下ajaxsubmit上傳文件提示下載文件問題 主要是應為放回類型為json&#xff0c;返回text/html轉載于:https://www.cnblogs.com/yang-C-J/p/8963278.html

一個簡單的 js 時間對象創建

JS中獲取時間很常見&#xff0c;湊湊熱鬧&#xff0c;也獲取一個時間對象試試 首先&#xff0c;先了解js的獲取時間函數如下&#xff1a; var myDate new Date(); //創建一個時間對象 myDate.getYear(); // 獲取當前年份&#xff08;2位&#x…

裁判打分_內在的裁判偏見

裁判打分News flash: being an umpire is hard. Their job is to judge whether a ball that’s capable of moving upwards of 100 MPH or breaking 25 inches crossed through an imaginary zone before being caught. I don’t think many would argue that they have it ea…

數據庫sql課程設計_SQL和數據庫-初學者完整課程

數據庫sql課程設計In this course, Mike Dane will teach you database management basics and SQL.在本課程中&#xff0c;Mike Dane將教您數據庫管理基礎知識和SQL。 The course starts off with Mike helping you install MySQL on Windows or Mac. Then he explores topic…

LCP 07. 傳遞信息

小朋友 A 在和 ta 的小伙伴們玩傳信息游戲&#xff0c;游戲規則如下&#xff1a; 有 n 名玩家&#xff0c;所有玩家編號分別為 0 &#xff5e; n-1&#xff0c;其中小朋友 A 的編號為 0 每個玩家都有固定的若干個可傳信息的其他玩家&#xff08;也可能沒有&#xff09;。傳信息…

微信公眾號自動回復加超鏈接最新可用實現方案

你在管理微信號時是否會有自動回復或者在關鍵字觸發自動回復加一個超鏈接的需求呢&#xff1f;例如下圖像王者榮耀這樣&#xff1a; 很多有開發經驗的朋友都知道微信管理平臺會類似富文本編輯器&#xff0c;第一想到的解決方案會是在編輯框中加<a href網址 >顯示文字<…

devops開發模式流程圖_2020 Web開發人員路線圖–成為前端,后端或DevOps開發人員的視覺指南

devops開發模式流程圖There are many ways you can go about picking up the skills you need to become a developer.您可以采用多種方法掌握成為開發人員所需的技能。 There are linear curriculums that teach you a bit of everything - like freeCodeCamps full stack de…

從Jupyter Notebook切換到腳本的5個理由

意見 (Opinion) 動機 (Motivation) Like most people, the first tool I used when started learning data science is Jupyter Notebook. Most of the online data science courses use Jupyter Notebook as a medium to teach. This makes sense because it is easier for be…