{
"question_id": 2046499, "question_title": "输入一组含n个元素的数据,求这组数据连续上升元素个数的最大值,请问下面代码哪里写错了?", "question_content": "输入一组含n个元素的数据,求这组数据连续上升元素个数的最大值,请问下面代码哪里写错了?", "difficulty": "简单", "answer_id": 11465862, "answer_content": "<pre>\n<code>#include <stdio.h>\nint main(){\n int n;\n while (scanf("%d",&n)!=EOF) {\n int t=0,sum=0,a[1000];\n for(int i=0; i<n; i++) {\n scanf("%d",&a[i]);\n }\n for(int i=1; i<n; i++) {\n if(a[i-1]<a[i]) {\n t++;\n if(sum<t)\n sum=t; //将最大的t赋值给sum \n } else\n t=0;\n }\n if(sum==0) {\n sum=0;\n } else sum=sum+1;\n printf("%d\\n",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"
}