简体   繁体   English

CodeChef 问题:最小最大

[英]CodeChef Problems: Minimum Maximum

I can't seem to understand why this code isn't yielding the correct answer on CodeChef.我似乎无法理解为什么这段代码没有在 CodeChef 上产生正确的答案。 When I run it on my machine.当我在我的机器上运行它时。 Seems to yield the correct cost似乎产生正确的成本

Problem Link: https://www.codechef.com/problems/MNMX问题链接: https : //www.codechef.com/problems/MNMX

using namespace std;

int main()
{
   unsigned int T, N, cost,element,del;
   std::cout<<"Enter the Test Cases";
   std::cin>>T;
   for (unsigned int i=0;i<T;i++){

        std::cout<<"Enter the size of the array";
        std::cin>>N;
        std::cout<<"Enter the values for "<<i+1<<" Test Case"<<endl;
        vector<int> first;
        std::cout<<"enter the values of the array"<<endl;
    for (unsigned int i=0;i<N;i++){
        std::cin>>element;
        first.push_back(element);
    }

   if (N>1){
    for (unsigned int i=0;i<N;i++){
        element = 0;
       element = min (first.front() , first[1]);
       del = max (first.front() , first[1]);
       first.erase(std::remove(first.begin(), first.end(), del), first.end());
        first.push_back(element);


   }
   }
   cost = first.front();
   std::cout<<"Cost: "<<cost<<endl;

}
return 0;
}

Generally this kind of test cases will not allow your logs to be part of this so please remove all cout statement except last, which you can modify like通常这种测试用例不允许您的日志成为其中的一部分,因此请删除除最后之外的所有 cout 语句,您可以像这样修改

std::cout << cost << std::endl;

Try this on codechef.在 codechef 上试试这个。

Or just edit last main output line as above.或者像上面一样编辑最后一个主输出行。

尝试在 for 循环中使用不同的迭代器变量,例如 j 和 k 用于内部循环。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM