Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int stadiumCapacity, fanCount, sectorA = 0, sectorB = 0, sectorV = 0, sectorG = 0;
- cin >> stadiumCapacity >> fanCount;
- char currentFanSector;
- for (int i = 0; i < fanCount; i++) {
- cin >> currentFanSector;
- if (currentFanSector == 'A') {
- sectorA++;
- }
- else if (currentFanSector == 'B') {
- sectorB++;
- }
- else if (currentFanSector == 'V') {
- sectorV++;
- }
- else {
- sectorG++;
- }
- }
- cout.setf(ios::fixed);
- cout.precision(2);
- cout << 100.0 * sectorA / fanCount << "%\n";
- cout << 100.0 * sectorB / fanCount << "%\n";
- cout << 100.0 * sectorV / fanCount << "%\n";
- cout << 100.0 * sectorG / fanCount << "%\n";
- cout << 100.0 * fanCount / stadiumCapacity << "%\n";
- return 0;
- }
- Решение с map, foreach и printf():
- #include <iostream>
- #include <map>
- #include <string>
- using namespace std;
- int main() {
- map <char, int> sectors = { {'A',0},{'B',0},{'V',0},{'G',0} };
- int stadiumCapacity, fanCount;
- cin >> stadiumCapacity >> fanCount;
- char currentFanSector;
- for (int i = 0; i < fanCount; i++) {
- cin >> currentFanSector;
- sectors[currentFanSector]++;
- }
- for (char sector : {'A', 'B', 'V', 'G'}) {
- printf("%.2f%%\n", 100.0 * sectors[sector] / fanCount);
- }
- printf("%.2f%%\n", 100.0 * fanCount / stadiumCapacity);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement