PAT Basic 1092 best to eat moon cake (20 points)

It is one of China's moon cake traditional cakes prestigious, since the Tang Dynasty, has developed hundreds of varieties.

mk.jpg

For competitions a kind of "best eating" moon cake, eat goods sector that is bound to lead to a reign of terror in ...... here we use the number of words, given the country a variety of moon cake sales, requiring you to find out the sales champion, identified as the best to eat moon cake.

Input formats:

First, given two input positive integers  N ( ≤) and  M ( ≤), respectively, the number of kinds of moon cake (so the default type moon cake from 1 to  N number) and the number of cities participating statistics.

Next  M rows, each row gives the  N non-negative integers (not exceeding 1 million), the first of which  i is the integer of  the i moon cake sales (block). Between numbers separated by a space.

Output formats:

The maximum output volume in the first row, the type of the highest-numbered second row output moon cake volume. If the winner is not unique, press the numbers in ascending order output tied for the championship. Between numbers separated by a space, the line from beginning to end may not have the extra space.

Sample input:

5 3
1001 992 0 233 6
8 0 2018 0 2008
36 18 0 1024 4

Sample output:

2018
3 5


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int row,column,tmp;
    vector<int> vec;
    cin>>column>>row;
    int val[column];
    fill(val,val+column,0);
    for(int i=0;i<row;i++)
        for(int j=0;j<column;j++){
            cin>>tmp;
            val[j]+=tmp;
        }
    int max_value=-1,coun=0;
    for(int i=0;i<column;i++)
        if(val[i]>max_value)
            max_value=val[i];
    cout<<max_value<<endl;
    for(int i=0;i<column;i++)
        if(val[i]==max_value)
            vec.push_back(i);
    for(int i=0;i<vec.size();i++)
        if(i!=vec.size()-1)cout<<vec[i]+1<<" ";
        else cout<<vec[i]+1;
    system("pause");
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/littlepage/p/11593486.html