Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- using namespace std;
- int main()
- {
- int visitors,
- back = 0,
- chest = 0,
- legs = 0,
- abs = 0,
- proteinBar = 0,
- proteinShake = 0;
- cin >> visitors;
- cin.ignore();
- string action;
- for (int i = 0; i < visitors; i++) {
- getline(cin, action);
- if (action == "Back") {
- back++;
- }
- else if (action == "Chest") {
- chest++;
- }
- else if (action == "Legs") {
- legs++;
- }
- else if (action == "Abs") {
- abs++;
- }
- else if (action == "Protein bar") {
- proteinBar++;
- }
- else {
- proteinShake++;
- }
- }
- cout << back << " - back\n"
- << chest << " - chest\n"
- << legs << " - legs\n"
- << abs << " - abs\n"
- << proteinShake << " - protein shake\n"
- << proteinBar << " - protein bar\n"
- << fixed << setprecision(2)
- << 100.0 * (back + chest + legs + abs) / visitors << "% - work out\n"
- << 100.0 * (proteinShake + proteinBar) / visitors << "% - protein\n";
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- #include <iomanip>
- #include <string>
- using namespace std;
- int main()
- {
- int visitors,
- back = 0,
- chest = 0,
- legs = 0,
- abs = 0,
- proteinBar = 0,
- proteinShake = 0;
- cin >> visitors;
- cin.ignore();
- string action;
- for (int i = 0; i < visitors; i++) {
- getline(cin, action);
- action == "Back" ? back++ :
- action == "Chest" ? chest++ :
- action == "Legs" ? legs++ :
- action == "Abs" ? abs++ :
- action == "Protein bar" ? proteinBar++ : proteinShake++;
- }
- cout << back << " - back\n"
- << chest << " - chest\n"
- << legs << " - legs\n"
- << abs << " - abs\n"
- << proteinShake << " - protein shake\n"
- << proteinBar << " - protein bar\n"
- << fixed << setprecision(2)
- << 100.0 * (back + chest + legs + abs) / visitors << "% - work out\n"
- << 100.0 * (proteinShake + proteinBar) / visitors << "% - protein\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement