<p>hi everyone,
i just started go today and was working through some problems from codeforces and am currently on this problem <a href="http://codeforces.com/problemset/problem/96/A" rel="nofollow">http://codeforces.com/problemset/problem/96/A</a>
and trying to do it with go but it says I cannot have a non constant length of array but I have no idea to work around this. If I could get some help thanks. Here is my code:
<script <a href="https://gist.github.com/gauravdesale/bb48bf0af6a9a1bb0813632bb56f66bd" rel="nofollow">https://gist.github.com/gauravdesale/bb48bf0af6a9a1bb0813632bb56f66bd</a></p>
<hr/>**评论:**<br/><br/>wybiral: <pre><p>You can define it as a slice and then "make" the array (allocate at runtime). <a href="https://play.golang.org/p/G7xuk8hiJu" rel="nofollow">https://play.golang.org/p/G7xuk8hiJu</a></p>
<p>But it will still fail because your i+j causes an array out-of-bounds access.</p>
<p>EDIT: I also changed some of your assignments. You only use ":=" to declare AND assign. So if you already used "var" to declare then don't use ":=" to assign (just use "="). Or just don't use "var" and declare with ":=".</p></pre>0xjnml: <pre><ul>
<li><a href="https://golang.org/ref/spec#Array_types" rel="nofollow">Array Types</a></li>
<li><a href="https://golang.org/ref/spec#Slice_types" rel="nofollow">Slice Types</a></li>
</ul></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传