8.json 1.9 KB
Newer Older
每日一练社区's avatar
test  
每日一练社区 已提交
1
{
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
  "question_id": 2046499,
  "question_title": "输入一组含n个元素的数据,求这组数据连续上升元素个数的最大值,请问下面代码哪里写错了?",
  "question_content": "输入一组含n个元素的数据,求这组数据连续上升元素个数的最大值,请问下面代码哪里写错了?",
  "difficulty": "简单",
  "answer_id": 11465862,
  "answer_content": "<pre>\n<code>#include &lt;stdio.h&gt;\nint main(){\n    int n;\n    while (scanf(&#34;%d&#34;,&amp;n)!&#61;EOF) {\n        int t&#61;0,sum&#61;0,a[1000];\n        for(int i&#61;0; i&lt;n; i&#43;&#43;) {\n            scanf(&#34;%d&#34;,&amp;a[i]);\n        }\n        for(int i&#61;1; i&lt;n; i&#43;&#43;) {\n            if(a[i-1]&lt;a[i]) {\n                t&#43;&#43;;\n                if(sum&lt;t)\n                    sum&#61;t;     //将最大的t赋值给sum \n            } else\n                t&#61;0;\n        }\n        if(sum&#61;&#61;0) {\n            sum&#61;0;\n        } else sum&#61;sum&#43;1;\n        printf(&#34;%d\\n&#34;,sum);\n    }\n    return 0;\n}</code></pre>\n\n<p> </p>",
  "tag_name": "c++",
  "cpp": "#include <stdio.h>\nint main(){\n\tint n;\n\twhile (scanf(\"%d\",&n)!=EOF) {\n\t\tint t=0,sum=0,a[1000];\n\t\tfor(int i=0; i<n; i++) {\n\t\t\tscanf(\"%d\",&a[i]);\n\t\t}\n\t\tfor(int i=1; i<n; i++) {\n\t\t\tif(a[i-1]<a[i]) {\n\t\t\t\tt++;\n\t\t\t\tif(sum<t)\n\t\t\t\t\tsum=t;\t \n\t\t\t} else\n\t\t\t\tt=0;\n\t\t}\n\t\tif(sum==0) {\n\t\t\tsum=0;\n\t\t} else sum=sum+1;\n\t\tprintf(\"%d\\n\",sum);\n\t}\n\treturn 0;\n}",
  "topic_link": "https://bbs.csdn.net/topics/600470246",
  "status": 0,
  "keywords": "算法初阶,最小值和最大值,排序和顺序统计量,中位数和顺序统计量",
  "license": "csdn.net",
  "notebook": {
    "cpp": "https://codechina.csdn.net/csdn/csdn-daily-code/-/jupyter/master/data/notebook/answer/ipynb/cpp/8.ipynb?type=file"
  },
  "author": "qq_34833730"
每日一练社区's avatar
test  
每日一练社区 已提交
18
}