有人能给我解决方案吗? [英] Can anyone give me the solution?

查看:94
本文介绍了有人能给我解决方案吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过但没有得到结果。 quies是 SPOJ.com - 问题SMPSEQ7 [ ^ ]



我的尝试:



i have tried but didn't get the result.quies is SPOJ.com - Problem SMPSEQ7[^]

What I have tried:

#include <iostream>
using namespace std;

int main() {
    int p,n,i,j,a[100],ctr;
 cin>>n;
 for(i=0;i<n;i++)
 cin>>a[i];
 for(i=0;i<n;i++)
 {  p=1;
     ctr=0;
     for(j=0;j<n;j++)
     {
         if(a[i]==a[j])
         {
             ctr++;
         }
     }
     if(ctr>=3||n==1)
     {   p=0;
         cout<<"No";
         break;
     }
 }
 if(p==1)
 cout<<"Yes";
	return 0;
}

推荐答案

没有。我们不做你的功课:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



我们给你解决方案并且你学习没有。你自己工作,你的技能提高。亲自尝试一下,你可能会发现它并不像你想象的那么困难!



如果你遇到一个具体的问题,那么请询问一下,我们会尽力而为帮助。但我们不打算为你做这一切!
No. We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

We "give you the solution" and you learn nothing. You get it working yourself, and your skills improve. Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!


引用:

我试过但是没有得到结果。

i have tried but didn't get the result.



您的问题是该代码与SPOJ问题无关。

建议:拿一张纸和一张纸铅笔并手动解决问题,创建更多具有更多数字的样本。你怎么看序列的一部分是减少还是增加。您需要做什么来查看下一个整数是否是当前递减序列的一部分?

如何手动执行它基本上是您必须转换为代码的算法。

您可以从检测序列是否正在减少开始。

-----

您的代码行为不符合您的预期,或者您不明白为什么!



有一个几乎通用的解决方案:一步一步地在调试器上运行你的代码,检查变量。

调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。

调试器中没有魔法,它不知道您的代码应该是什么做,它没有发现错误,它只是通过向您展示正在发生的事情来帮助您。当代码没有达到预期的效果时,你就接近了一个错误。

要查看你的代码在做什么:只需设置断点并查看代码是否正常运行,调试器允许你执行第1行第1行,并在执行时检查变量。

调试器 - 维基百科,免费的百科全书 [ ^ ]



掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]

使用Visual Studio 2010进行基本调试 - YouTube [ ^ ]

1.11 - 调试程序(步进和断点)|学习C ++ [ ^ ]

调试器仅显示您的代码正在执行的操作,并且您的任务是与应该执行的操作进行比较。


Your problem is that the code is not related to the SPOJ question.
Advice: take a sheet of paper and a pencil and solve the problem by hand, create more samples with more numbers. How do you see if a part of sequence is decreasing or increasing. What do you need to do to see if next integer is part of the current decreasing sequence ?
How you do it by hand is basically your algorithm that you have to translate to code.
You can start with just detecting if a sequence is decreasing or not.
-----
Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.
Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
1.11 — Debugging your program (stepping and breakpoints) | Learn C++[^]
The debugger is here to only show you what your code is doing and your task is to compare with what it should do.


这篇关于有人能给我解决方案吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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