99 Bottles of Beer
„99 Bottles of Beer” – piosenka angielska, zazwyczaj śpiewana w czasie długich podróży w celu „zabicia czasu”.
- 99 bottles of beer on the wall, 99 bottles of beer. Take one down and pass it around - 98 bottles of beer on the wall.
- 98 bottles of beer on the wall, 98 bottles of beer. Take one down and pass it around - 97 bottles of beer on the wall.
- ...
- 2 bottles of beer on the wall, 2 bottles of beer. Take one down and pass it around - 1 bottle of beer on the wall.
- 1 bottle of beer on the wall, 1 bottle of beer. Take it down and pass it around - no more bottles of beer on the wall.
- 98 bottles of beer on the wall, 98 bottles of beer. Take one down and pass it around - 97 bottles of beer on the wall.
Każda linijka, z wyjątkiem ostatnich, różni się tylko liczbą butelek piwa. Istnieje wiele odmian tej piosenki. Niektórzy na końcu dodają jeszcze jeden wers, po którym można zacząć całość od początku:
- No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, 99 bottles of beer on the wall.
Generowanie tego wierszyka jest jednym ze standardowych zadań, na których demonstruje się składnię języków programowania.
Przykłady w programowaniu
Język Pascal
uses crt;
var
a:integer;
begin
a:=99;
repeat
write(a);
write(' bottles of beer on the wall, ');
write(a);
write(' bottles of beer. Take one down and pass it around - ');
a:=a-1;
write(a);
writeln('bottles of beer on the wall.');
until a=2;
writeln('2 bottles of beer on the wall, 2 bottles of beer. Take one down and pass it around - 1 bottle of beer on the wall.');
writeln('1 bottle of beer on the wall, 1 bottle of beer. Take it down and pass it around - no more bottles of beer on the wall.');
repeat until keypressed;
end.
Język C++
#include <iostream>
using namespace std;
int main()
{
int x = 99;
while (x > 0)
{
if (x > 2)
{
cout << x << " bottles of beer on the wall, " << x << " bottles of beer. "
<< "Take one down and pass it around - " << x - 1 << " bottles of beer on the wall.\n";
}
else if (x == 2)
{
cout << x << " bottles of beer on the wall, " << x << " bottles of beer. "
<< "Take one down and pass it around - " << x - 1 << " bottle of beer on the wall.\n";
}
else
{
cout << x << " bottle of beer on the wall, " << x << " bottle of beer. "
<< "Take one down and pass it around - no more bottles of beer on the wall.\n";
}
x--;
}
}
Język C#
void Main(){
for (int i = 99; i > 1; i--){
Console.WriteLine(i + "bottles of beer on the wall, " + i + " bottles of beer. Take one down and pass it around - " + i - 1 + "bottles of beer on the wall.");
}
Console.WriteLine("1 bottle of beer on the wall, 1 bottle of beer. Take it down and pass it around - no more bottles of beer on the wall.");
}
bash
for bottles in $(seq 99 -1 3); do echo $bottles bottles of beer on the wall, $bottles bottles of beer. Take one down and pass it around - $(($bottles-1)) bottles of beer on the wall.; sleep 1; done; echo 2 bottles of beer on the wall, 2 bottles of beer. Take one down and pass it around - 1 bottle of beer on the wall.; echo 1 bottle of beer on the wall, 1 bottle of beer. Take it down and pass it around - no more bottles of beer on the wall.;
Python
for i in range(99, 0, -1):
if i == 1:
print('1 bottle of beer on the wall, 1 bottle of beer!')
print('So take it down, pass it around, no more bottles of beer on the wall!')
elif i == 2:
print('2 more bottles of beer on the wall, 2 more bottles of beer!')
print('So take one down, pass it around, 1 more bottle of beer on the wall!')
else:
print('{0} bottles of beer on the wall, {0} bottles of beer!'.format(i))
print('So take it down, pass it around, {0} more bottles of beer on the wall!'.format(i - 1))
JavaScript
function bottlesOfBeer() {
for (let i=99; i>=0; i--) {
var lasts = i-1;
if (i == 2) {
console.log(i + " bottles of beer on the wall, " + i + " bottles of beer. Take one down and pass it around - " + lasts + " bottle of beer on the wall.");}
else if (i == 1) {
console.log(i + " bottle of beer on the wall, " + i + " bottle of beer. Take it down and pass it around - no more bottles of beer on the wall.");}
else if (i == 0) {
console.log("No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, 99 bottles of beer on the wall.");}
else {
console.log(i + " bottles of beer on the wall, " + i + " bottles of beer. Take one down and pass it around - " + lasts + " bottles of beer on the wall.");}
}
}
Zobacz też
Linki zewnętrzne
- 99 Bottles of Beer w ponad 1000 języków programowania (ang.)
- 99 Bottles of Beer na stronie RosettaCode.org (ang.)