aboutsummaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
Diffstat (limited to 'c')
-rw-r--r--c/128_Florencia.cpp25
1 files changed, 14 insertions, 11 deletions
diff --git a/c/128_Florencia.cpp b/c/128_Florencia.cpp
index 4346fa0..32e221a 100644
--- a/c/128_Florencia.cpp
+++ b/c/128_Florencia.cpp
@@ -6,38 +6,41 @@ int main() {
int size;
int sides, parts, length;
int totalPieces, rest, remainingSize;
- int imposibleFlag;
+ int impossibleFlag;
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;
+ impossibleFlag = 0;
+ cin >> sides;
while (sides != -1) {
cin >> parts;
cin >> length;
- if (length > size && !imposibleFlag) {
+ if (length > size && !impossibleFlag) {
cout<<"IMPOSIBLE\n";
- imposibleFlag = 1;
+ impossibleFlag = 1;
}
- else {
+ else if (!impossibleFlag) {
for (int i = 0; i < sides * parts; i++ ) {
if (remainingSize >= length)
remainingSize -= length;
else {
rest += remainingSize;
- cout<<"Added "<<remainingSize<<" to rest.\n";
- remainingSize = size;
+ remainingSize = size - length;
totalPieces++;
}
}
}
cin >> sides;
}
- if (remainingSize == size)
- totalPieces--;
- if (!imposibleFlag)
+ if (remainingSize != size)
+ rest += remainingSize;
+ else { // Se ejecuta cuando no se ha usado nada de varilla (remainingSize nunca vuelve a ser size).
+ totalPieces = 0;
+ rest = 0;
+ }
+ if (!impossibleFlag)
cout<<totalPieces<<" "<<rest<<endl;
cin >> size;
}