注册 登录
编程论坛 C++教室

看不懂编译器给的错误

frafish 发布于 2019-07-19 21:31, 1444 次点击
这是我的code:
题目出处:https://zerojudge.tw/ShowProblem?problemid=c044


#include<iostream>
using namespace std;
void fn_a( int& times, int& finish )
{
    int maxv=0;
    char alpha[26]{ 'A','B','C','D','E','F','G','H','I','J','K','l','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
    for( int i=0; i<26; ++i )
        if( maxv<times[i] ) maxv=times[i];
    for( int i=0; i<26; ++i ){
        if( times[i]==maxv ) cout << alpha[i] << ' ' << times[i] << endl;
        times[i]=0;
        finish++;
    }
}

int main()
{
    int n;
    while( cin>>n ){
        int times[26];
        for( int i=0; i<26; ++i ) times[i]=0;
        string sum="";
        for( int i=0; i<n; ++i ){
            string s;
            cin >> s;
            sum+=s;
        }
        int length=sum.length()-1;
        for( int i=0; i<length; ++i ) times[sum[i]]++;
        int finish=0;
        while( finish<=26 )
            fn_a( *times, *finish );
    }
    return 0;
}

编译器给的错误是什么意思啊?????!!!!!!
只有本站会员才能查看附件,请 登录

还一直重复出现,估计问题满大的

2 回复
#2
rjsp2019-07-20 11:29
void fn_a( int& times, int& finish )
改为 void fn_a( int times[], int& finish )

fn_a( *times, *finish );
改为 fn_a( times, finish );

我按照题意写了一个,没发提交,所以不知道对或错
程序代码:
#include <iostream>
#include <limits>
#include <algorithm>
#include <utility>
using namespace std;

int main( void )
{
    size_t n;
    cin >> n;
    cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );

    pair<char,size_t> buf[26];
    generate_n( buf, 26, [c='A']()mutable{return make_pair(c++,0);} );

    for( char c; n!=0 && cin.get(c); )
    {
        if( c>='A' && c<='Z' )
            ++buf[c-'A'].second;
        else if( c>='a' && c<='z' )
            ++buf[c-'a'].second;
        else if( c == '\n' )
            --n;
    }

    auto p = remove_if( buf, buf+26, [](const auto& e){return e.second==0;} );
    sort( buf, p, [](const auto& a, const auto& b) {
                      if( a.second > b.second ) return true;
                      if( a.second < b.second ) return false;
                      return a.first < b.first; } );
    for_each( buf, p, [](const auto& e){cout<<e.first<<' '<<e.second<<'\n';} );
}

#3
frafish2019-07-20 12:54
回复 2楼 rjsp
你这个也太高级了吧,完全看不懂
1