diff options
author | InigoGutierrez <inigogf.95@gmail.com> | 2019-05-28 21:18:05 +0200 |
---|---|---|
committer | InigoGutierrez <inigogf.95@gmail.com> | 2019-05-28 21:18:05 +0200 |
commit | 4ef1833c653112986d01d1d453fd67a2fbb21216 (patch) | |
tree | 7dc7b197c7e54552f07bc73dfdebd0e6dd7bb886 /c/128_Florencia.cpp | |
parent | 8627bfbf0fbc2a49006b375072fd3815edd5e460 (diff) | |
download | AceptaElReto-4ef1833c653112986d01d1d453fd67a2fbb21216.tar.gz AceptaElReto-4ef1833c653112986d01d1d453fd67a2fbb21216.zip |
Resuelto 128 en c++: Florencia.
Diffstat (limited to 'c/128_Florencia.cpp')
-rw-r--r-- | c/128_Florencia.cpp | 25 |
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; } |