mercredi 16 décembre 2020

University project

KIndly find pictures explaining the task. My code is below, it doesn't compile.

enter image description here

enter image description here

We know the colors appearing in the flags of some countries (the data is given with pairs: country identifier, a color in the flag). Multiple data pairs are given for flags containing more than one color. We form groups of countries whose flags contain exactly the same colors.

Write a program that determines the following:

  1. The total number of different colors appearing in the flags.
  2. A color that only appears in one flag.
  3. For every color, the number of flags containing it.
  4. The country whose flag contains the most colors.
  5. How many groups of countries can be made according to the principle in the task description?

Input

The first line of the standard input contains the number of countries (1≤C≤1000), and the number of data pairs (1≤D≤2000). In the next D*2 lines, there is a data pair in every two lines: a color (a word with at most 10 letters of the English alphabet), and the identifier number of a country (1≤Ki≤C) whose flag contains the given color. A flag contains at most 10 colors, the number of different colors does not exceed 1000.

Output

The standard output should contain a line with a single # character before the solution of each subtask. This # character line is followed by as many lines as needed for the output of a subtask. If you cannot solve a subtask, you should output only the line containing the # character. If the output format is not correct (less/more # characters are in the output), you will get “Output format error”, even if you have correct solutions for some subtasks.

Subtask 1 (15 points): Print the total number of different colors appearing in the flags.

Subtask 2 (20 points): A single line should contain a color that appears only in one flag. In case of multiple possible answers, you can print any of them. If there is no such color, then print the word NONE.

Subtask 3 (20 points): Print a line for each color (in any order). Every line should contain a color and the count of flags containing that color.

Subtask 4 (15 points): Print the identifier of the country whose flag contains the most colors. In case of multiple possible solutions, you must give the one with the smallest identifier.

Subtask 5 (30 points) Print how many groups are created of countries whose flags contain exactly the same colors

#include <iostream>
#include <vector>
using namespace std;

struct flags{
    int colors, identifier_of_country, day;
};

int main()
{
    int n;
    cerr << "Count of flags (1-100): ";
    cin >> n;
    while (n < 1 || n > 100) {
        cerr << "Wrong input" << endl;
        cerr << "Count of flags (1-100): ";
        cin >> n;
    }
    flags flag[n];
    for (int i = 0; i < n; i++) {
        cerr << "The  colors of person " << i + 1 << "  ): ";
        cin >>  flag[i].colors;
        while ( flag[i].colors < 1950 ||  flag[i].colors > 2000) {
            cerr << "Wrong input" << endl;
            cerr << "The  colors of person " << i + 1 << "  ): ";
            cin >>  flag[i].colors;
        }

        cerr << "The  identifier_of_country of person " << i + 1 << " (1-12): ";
        cin >>  flag[i].identifier_of_country;
        while ( flag[i].identifier_of_country < 1 ||  flag[i].identifier_of_country > 12) {
            cerr << "Wrong input" << endl;
            cerr << "The  identifier_of_country of person " << i + 1 << " (1-12): ";
            cin >>  flag[i].identifier_of_country;
        }

        cerr << "The  day of person " << i + 1 << " (1-30): ";
        cin >>  flag[i].day;
        while ( flag[i].day < 1 ||  flag[i].day > 30) {
            cerr << "Wrong input" << endl;
            cerr << "The  day of person " << i + 1 << " (1-30): ";
            cin >>  flag[i].day;
        }

        int start_colors,  flag_colour;
        cerr << "The start colors of person " << i + 1 << " (2000-2019): ";
        cin >> start_colors;
        while (start_colors < 2000 || start_colors >= 2020) {
            cerr << "Wrong input" << endl;
            cerr << "The start colors of person " << i + 1 << " (2000-2019): ";
            cin >> start_colors;
        }

        cerr << "The graduation colors of person " << i + 1
                << " (" << start_colors << "-2019): ";
        cin >>  flag_colour;
        while ( flag_colour < start_colors ||  flag_colour >= 2020) {
            cerr << "Wrong input" << endl;
            cerr << "The graduation colors of person " << i + 1
                    << " (" << start_colors << "-2019): ";
            cin >>  flag_colour;
        }
    }

    int counter[4] = {0};
    for (int i = 0; i < n; i++) {
        counter[( flag[i].identifier_of_country % 12) / 3]++;
        // spring 3,4,5 / 3 = 1; summer 6,7,8 / 3 = 2
        // autumn 9,10,11 / 3 = 3; winter 1,2,0 / 3 = 0
    }
    cerr << "The number of people born in spring, summer, autumn, winter: ";
    cout << counter[1] << " " << counter[2] << " "
            << counter[3] << " " << counter[0];

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire