0分(RE),可是目测无错

回复帖子

@爷爷是我 2019-03-26 18:51 回复
#include <iostream>
#include <string>
using namespace std;

void count(string input) {

    int count[26] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };

    for (int i = 0; i < input.length(); i++) {
        switch (input[i]) {
        case 'A':
            count[0]++;
            break;
        case 'B':
            count[1]++;
            break;
        case 'C':
            count[2]++;
            break;
        case 'D':
            count[3]++;
            break;
        case 'E':
            count[4]++;
            break;
        case 'F':
            count[5]++;
            break;
        case 'G':
            count[6]++;
            break;
        case 'H':
            count[7]++;
            break;
        case 'I':
            count[8]++;
            break;
        case 'J':
            count[9]++;
            break;
        case 'K':
            count[10]++;
            break;
        case 'L':
            count[11]++;
            break;
        case 'M':
            count[12]++;
            break;
        case 'N':
            count[13]++;
            break;
        case 'O':
            count[14]++;
            break;
        case 'P':
            count[15]++;
            break;
        case 'Q':
            count[16]++;
            break;
        case 'R':
            count[17]++;
            break;
        case 'S':
            count[18]++;
            break;
        case 'T':
            count[19]++;
            break;
        case 'U':
            count[20]++;
            break;
        case 'V':
            count[21]++;
            break;
        case 'W':
            count[22]++;
            break;
        case 'X':
            count[23]++;
            break;
        case 'Y':
            count[24]++;
            break;
        case 'Z':
            count[25]++;
            break;
        }
    }

    int max = 0;
    string alphabet[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 (count[i] >= max) {
            max = count[i];
        }
    }

    for (int j = 0; j < max; j++) {

        int last = 0;
        for (int i = 0; i < 26; i++) {
            if (count[i] >= (max - j)) {
                last = i;
            }
        }

        for (int i = 0; i <= last; i++) {
            if ((max - j - count[i]) > 0) {
                if (i != last) {
                    cout << "  ";
                }
                else { cout << ""; }
            }
            else {
                if (i != last) {
                    cout << "* ";
                }
                else {
                    cout << "*";
                }
            }
        }
        cout << endl;
    }

    for (int i = 0; i < 26; i++) {
        if (i != 25) {
            cout << alphabet[i] << " ";
        }
        else {
            cout << alphabet[i];
        }
    }

}

int main()
{
    string line1[100], line2[100], line3[100], line4[100];
    int line1Len, line2Len, line3Len, line4Len;

    string temp="";

    for (int i = 0; i < 100; i++)
    {
        cin >> line1[i];
        if (cin.get() == '\n') { 
            line1Len = i+1; 
            break; 
        }
    }

    for (int i = 0; i < 100; i++)
    {
        cin >> line2[i];
        if (cin.get() == '\n') {
            line2Len = i + 1; 
            break; 
        }
    }

    for (int i = 0; i < 100; i++)
    {
        cin >> line3[i];
        if (cin.get() == '\n') {
            line3Len = i + 1; 
            break; }
    }

    for (int i = 0; i < 100; i++)
    {
        cin >> line4[i];
        if (cin.get() == '\n') {
            line4Len = i + 1; 
            break; }
    }

    for (int i = 0; i < line1Len; i++) {
        temp += line1[i];
    }

    for (int i = 0; i < line2Len; i++) {
        temp += line2[i];
    }

    for (int i = 0; i < line3Len; i++) {
        temp += line3[i];
    }

    for (int i = 0; i < line4Len; i++) {
        temp += line4[i];
    }

    count(temp);

}
反馈
如果你认为某个帖子有问题,欢迎向洛谷反馈,以帮助更多的同学。



请具体说明理由,以增加反馈的可信度。