aboutsummaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
authorInigoGutierrez <inigogf.95@gmail.com>2019-05-28 19:44:30 +0200
committerInigoGutierrez <inigogf.95@gmail.com>2019-05-28 19:44:30 +0200
commit8627bfbf0fbc2a49006b375072fd3815edd5e460 (patch)
treedaa50459c0fa3b0fd887e6e782d10b108c2d539a /c
parenta0164a1487fd419b88718cad4b20fab65e93e865 (diff)
downloadAceptaElReto-8627bfbf0fbc2a49006b375072fd3815edd5e460.tar.gz
AceptaElReto-8627bfbf0fbc2a49006b375072fd3815edd5e460.zip
Trying to solve 128_Florencia.
Diffstat (limited to 'c')
-rw-r--r--c/128_Florencia.cpp44
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;
+ }
+}