Advertisement
JosepRivaille

P12943: Control C202C

Feb 26th, 2015
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. //Pre: Llegeix el nombre de preguntes i la resposta a cada una
  6. //Post: Obté la resposta més repetida i quantes n'hi ha
  7. int main() {
  8.   int n, ca, cb, cc;
  9.   ca = cb = cc = 0;
  10.   char x;
  11.   cin >> n;
  12.   while (n != 0) {
  13.     cin >> x;
  14.     if (x == 'a') ++ca;
  15.     else if (x == 'b') ++cb;
  16.     else if (x == 'c') ++cc;
  17.     --n;
  18.   }
  19.   if (ca >= cb && ca >= cc) {
  20.     cout << "majoria de a" << endl;
  21.     cout << ca << " repeticio(ns)" << endl;
  22.   }else if (cb >= ca && cb >= cc) {
  23.     cout << "majoria de b" << endl;
  24.     cout << cb << " repeticio(ns)" << endl;
  25.   }else {
  26.     cout << "majoria de c" << endl;
  27.     cout << cc << " repeticio(ns)" << endl;
  28.   }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement