首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

求改错解决办法

2012-04-07 
求改错题目描述:输入10个数,要求输出其中的最大值。输入:测试数据有多组,每组10个数。输出:对于每组输入,请

求改错
题目描述: 
输入10个数,要求输出其中的最大值。

输入: 
测试数据有多组,每组10个数。

输出: 
对于每组输入,请输出其最大值(有回车)。

样例输入: 
10 22 23 152 65 79 85 96 32 1样例输出: 
max=152


以下程序在oj为WA,哪里错了?

#include <cstdlib>
#include <iostream>
using namespace std;

int main(int argc, char *argv[])
{
  int n;
  cin>>n;
  int max;
  for(int i=0;i<n;i++)
  {
  int m;
  cin>>m;
  max=m;
  for(int j=1;j<10;j++)
  {
  cin>>m;
  if(m>max)max=m;
  }  
  cout<<"max="<<max<<endl;  
  }
  return 0;
}


[解决办法]
楼主你验证过你的程序没?结果正确的吗?
改下吧

C/C++ code
#include <cstdlib>#include <iostream>using namespace std;int main(int argc, char *argv[]){  int n;  cin>>n;  int max;  int m;  cin>>m;  max=m;  for(int j=2;j<10;j++)  {      cin>>m;      if(m>max)          max=m;  }     cout<<"max="<<max<<endl;     return 0;}
[解决办法]
C/C++ code
#include <cstdlib>#include <iostream>using namespace std;int main(int argc, char *argv[]){    const int n = 10;    int max = 0;    int a;    for(int i=0; i < n; i++)    {        cin>>a;        if (a > max)        {            max = a;        }    }        cout<<"max: "<<max<<endl;    system("pause");    return 0;} 

热点排行