0

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";
}
cigien
  • 57,834
  • 11
  • 73
  • 112
  • 1
    Even when programming for so-called "competition" or "online judge" sites, please use good habits and write good code. And don't use such sites for learning programming or languages, as that's not their purpose. All that seems to be taught are bad habits and invalid code (yes, your code isn't valid C++). If you really want to learn programming and C++, then forget everything from such sites, invest in [some good books](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list/388282#388282) and take classes. – Some programmer dude Dec 14 '21 at 08:48
  • Please confirm that this is for code-golfing and that you need to minimise code length further at any cost. – Yunnosch Dec 14 '21 at 14:53

0 Answers0