如何在C ++中编写此代码 [英] How can I write this code in C++

查看:71
本文介绍了如何在C ++中编写此代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1 2 6 7 15

3 5 8 14

4 9 13

10 12

11



我尝试了什么:



我尝试编码c ++但我无法理解什么是

1 2 6 7 15
3 5 8 14
4 9 13
10 12
11

What I have tried:

I try to code it in c++ but i cant understand what relationship is

推荐答案

cout << "1 2 6 7 15" << endl;
cout << "3 5 8 14" << endl;
cout << "4 9 13" << endl;
cout << "10 12" << endl;
cout << "11" << endl;

应该这样做。


这不是关系,它是一种模式。从1开始,然后按照行格往

It's not a "relationship", it's a pattern. Start at 1 and follow the line
1-2  6-7 15
 /  / / /
3  5 8 14
| / / /
4  9 13
  / /
10 12
| /
11

按照向右,向左,向下,然后向上,向上的模式按顺序写入数字1到15重复直到结束。

更容易看出你是否稍微旋转三角形:

You write the numbers 1 to 15 in order following the pattern "go right, then left and down, then down, then right and up" Repeat until you get to the end.
It's easier to see if you rotate the triangle a little:

        1
      3  2
    4  5  6
  10 9  8  7
11 12 13 14 15

每行交替方向,并增加你输出的数字。



考虑一下 - 确定要做什么是你的任务的一部分,它旨在让你考虑一般的解决方案,以及如何将它们从需求转换为可以实现的功能描述。



你会到达那里,想一想(可能还有一些错误的开始 - 不要害怕废弃它并重新开始,但要保持旧的副本,以防你改变主意。)

Each row alternates direction, and increases the "number of numbers" you output.

Think about it for a bit - working out what to do is part of your task, it's designed to get you thinking about solutions in general, and how you translate them from a requirement into a functional description you can implement.

You'll get there, with a bit of thought (and probably a few false starts - don't be afraid to scrap it and start again, but keep old copies in case you change your mind).


这篇关于如何在C ++中编写此代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆