Skip to content

Instantly share code, notes, and snippets.

@dev4dev
Last active December 12, 2015 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dev4dev/4696628 to your computer and use it in GitHub Desktop.
Save dev4dev/4696628 to your computer and use it in GitHub Desktop.
//
// main.cpp
// prob344
//
// Created by Alex Antonyuk on 2/1/13.
// Copyright (c) 2013 Alex Antonyuk. All rights reserved.
//
#include <iostream>
using namespace std;
const int pointsCount = 9;
int points[pointsCount] = {100, 90, 50, 40, 10, 9, 5, 4, 1};
const int valuesCount = 5;
int result[valuesCount] = {
0, // i
0, // v
0, // x
0, // l
0, // c
};
char chars[valuesCount] = {'i', 'v', 'x', 'l', 'c'};
int char_values[][valuesCount] = {
/* i v x l c */
{0, 0, 0, 0, 1}, // 100
{0, 0, 1, 0, 1}, // 90
{0, 0, 0, 1, 0}, // 50
{0, 0, 1, 1, 0}, // 40
{0, 0, 1, 0, 0}, // 10
{1, 0, 1, 0, 0}, // 9
{0, 1, 0, 0, 0}, // 5
{1, 1, 0, 0, 0}, // 4
{1, 0, 0, 0, 0}, // 1
};
void reset_result()
{
for (int i = 0; i < valuesCount; ++i) {
result[i] = 0;
}
}
void add_value_to_result(int* value, int times)
{
for (int i = 0; i < valuesCount; ++i) {
result[i] += value[i] * times;
}
}
void calc(int number)
{
reset_result();
int workNumber = 0;
for (int n = number; n > 0; --n) {
int numerator = 0;
workNumber = n;
for (int index = 0; index < pointsCount; ++index) {
numerator = workNumber / points[index];
add_value_to_result(char_values[index], numerator);
workNumber -= points[index] * numerator;
}
}
}
int main(int argc, const char * argv[])
{
int number = 0;
while (cin >> number && number > 0 && number <= 100) {
calc(number);
cout << number << ": ";
for (int i = 0; i < valuesCount; ++i) {
cout << result[i] << " ";
cout << chars[i] << ((i < valuesCount - 1) ? ", " : "");
}
cout << "\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment