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.mzph.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…