1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8" /> 5 <title>逻辑推理</title> 6 </head> 7 <body> 8 <script> 9 /* 10 一个人去买汽水,1块钱一瓶,三个瓶盖可以换一瓶汽水,2个空瓶可以换一瓶汽水 请问 20块钱 11 总共能买到多少瓶汽水? 12 */ 13 var money; //金钱 14 var bottle = 20; //瓶子 15 var cap = 20; //盖子 16 var sum = 20; //总共换的饮料 17 var drink; //总共喝的饮料 18 for (var i = 0; i < 20; i++) { 19 drink = parseInt(bottle / 2) + parseInt(cap / 3); 20 cap = drink + (cap % 3); 21 bottle = drink + (bottle % 2); 22 sum += drink; 23 document.write( 24 "第", 25 i + 1, 26 "次能换: 瓶:" + bottle + " 盖:" + cap + " 饮料:" + drink + "<br>" 27 ); 28 if (drink == 0) { 29 document.write("<h3>总共能换" + sum + "瓶饮料<h3>"); 30 break; 31 } 32 } 33 </script> 34 </body> 35 </html>
标签:汽水,20,bottle,drink,一瓶,块钱,var From: https://www.cnblogs.com/cqy6715/p/17082297.html