aropan

Римская система счисления

Feb 23rd, 2011
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. ...
  2. string C[MAXR] = {"I", "V", "X", "L", "C", "D", "M"};
  3. int X[MAXR] = {1, 5, 10, 50, 100, 500, 1000};
  4. ...
  5.     R.clear();
  6.     for (int i = 0; i < MAXR; i++)
  7.         R.push_back(make_pair(X[i], C[i]));
  8.  
  9.     for (int i = 0; i < MAXR; i += 2)
  10.         for (int j = i + 1; j < i + 3 && j < MAXR; j++)
  11.             R.push_back(make_pair(X[j] - X[i], C[i] + C[j]));
  12.  
  13.     sort(R.rbegin(), R.rend());
  14.  
  15.     for (int i = 0; i < (int)R.size(); i++)
  16.     {
  17.         for (int j = 0; j < x / R[i].first; j++)
  18.             cout << R[i].second;
  19.         x %= R[i].first;
  20.     }
  21.     cout << endl;
  22. ...
Add Comment
Please, Sign In to add comment