Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- 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++;
- }
- }
- printf("%.2f%%\n", 100.0 * sectorA / fanCount);
- printf("%.2f%%\n", 100.0 * sectorB / fanCount);
- printf("%.2f%%\n", 100.0 * sectorV / fanCount);
- printf("%.2f%%\n", 100.0 * sectorG / fanCount);
- printf("%.2f%%\n", 100.0 * fanCount / stadiumCapacity);
- return 0;
- }
- Решение с колекция и for(each):
- #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