diff options
Diffstat (limited to 'c/128_Florencia.cpp')
-rw-r--r-- | c/128_Florencia.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/c/128_Florencia.cpp b/c/128_Florencia.cpp new file mode 100644 index 0000000..4346fa0 --- /dev/null +++ b/c/128_Florencia.cpp @@ -0,0 +1,44 @@ +#include <iostream> + +using namespace std; + +int main() { + int size; + int sides, parts, length; + int totalPieces, rest, remainingSize; + int imposibleFlag; + cin >> size; // Primera lectura del tamaƱo fuera del bucle para primera comprobaciĆ³n + while (size != -1) { + totalPieces = 1; + rest = 0; + cin >> sides; + imposibleFlag = 0; + remainingSize = size; + while (sides != -1) { + cin >> parts; + cin >> length; + if (length > size && !imposibleFlag) { + cout<<"IMPOSIBLE\n"; + imposibleFlag = 1; + } + else { + for (int i = 0; i < sides * parts; i++ ) { + if (remainingSize >= length) + remainingSize -= length; + else { + rest += remainingSize; + cout<<"Added "<<remainingSize<<" to rest.\n"; + remainingSize = size; + totalPieces++; + } + } + } + cin >> sides; + } + if (remainingSize == size) + totalPieces--; + if (!imposibleFlag) + cout<<totalPieces<<" "<<rest<<endl; + cin >> size; + } +} |