mardi 14 décembre 2021

Why does this give my empty output file for my C++ code in USACO?

the final test case says to output the word "Tie" when there is 2 or more cows who produce the second-least amount of milk. In my program, i clearly wrote a program for that case. here is the code, if it helps

#include <bits/stdc++.h>
using namespace std;
int main()
{
    freopen("notlast.in","r", stdin); 
    freopen("notlast.out","w", stdout);
    int n,values;
    cin>>n;
    int cowvalues[7]={0};
    string cowss[n],cows[7]={"Bessie", "Elsie", "Daisy", "Gertie", "Annabelle", "Maggie", "Henrietta"};
    for(int i=0;i<n;++i){
        cin>>cowss[i]>>values;
        for(int j=0;j<7;++j){
            if(cowss[i]==cows[j])
            {
                cowvalues[j]+=values;
            }
        }
    }
    for(int i=0;i<6;++i){
        for(int j=0;j<6-i;++j){
            if(cowvalues[j]>cowvalues[j+1])
            {
                swap(cowvalues[j],cowvalues[j+1]);
                swap(cows[j],cows[j+1]);
            }
        }
    }
    int a=1;
    while(cowvalues[a]==cowvalues[0])   a++;
    if(cowvalues[a+1]==cowvalues[a])    cout<<"Tie\n";
    else    cout<<cows[a]<<"\n";
}

Aucun commentaire:

Enregistrer un commentaire