Schachbrett (Schleifen)
Schreiben Sie ein Programm, das die Nummerierung eines Schachbretts in der folgenden Form ausgibt:
A8 B8 C8 D8 E8 F8 G8 H8
A7 B7 C7 D7 E7 F7 G7 H7
A6 B6 C6 D6 E6 F6 G6 H6
A5 B5 C5 D5 E5 F5 G5 H5
A4 B4 C4 D4 E4 F4 G4 H4
A3 B3 C3 D3 E3 F3 G3 H3
A2 B2 C2 D2 E2 F2 G2 H2
A1 B1 C1 D1 E1 F1 G1 H1
Bemerkung: Die ursprüngliche Aufgabenstellung war falsch (spiegelverkehrt):
H1 H2 H3 H4 H5 H6 H7 H8
G1 G2 G3 G4 G5 G6 G7 G8
F1 F2 F3 F4 F5 F6 F7 F8
E1 E2 E3 E4 E5 E6 E7 E8
D1 D2 D3 D4 D5 D6 D7 D8
C1 C2 C3 C4 C5 C6 C7 C8
B1 B2 B3 B4 B5 B6 B7 B8
A1 A2 A3 A4 A5 A6 A7 A8
Daher liefern einige "Musterlösungen" auch dieses Resultat.
1 Kommentare
56 Lösung(en)
- ruby
- java
- c
- pl1
- pl1
- pl1
- haskell
- python
- python
- php
- python
- csharp
- python
- csharp
- javascript
- java
- java
- cpp
- perl
- cpp
- python
- vb
- pascal
- shell
- generic
- java
- ruby
- perl
- lisp
- perl
- c
- text
- perl
- javascript
- php
- c
- java
- python
- cpp
- java
- generic
- shell
- generic
- perl
- python
- c
- python
- csharp
- python
- generic
- csharp
- cpp
- csharp
- generic
- csharp
- cpp
('A'..'H').reverse_each do |ele|
8.times do |i|
print ele, i+1, ' '
end
puts
end
Lösung von: Name nicht veröffentlicht
package ch.programmieraufgaben.iteration.schachbrett;
public class Schachbrett {
public static void main(String[] args) {
new Schachbrett().top();
}
void top() {
char zeile = 'H';
while(zeile >= 'A') {
char spalte = '1';
while(spalte <= '8') {
System.out.print("" + zeile + spalte + " ");
spalte = (char) (spalte + 1);
}
System.out.println();
zeile = (char) (zeile - 1);
} //
} // end methode "top()"
} // end class: Schachbrett
Lösung von: Philipp G. Freimann (BBW (Berufsbildungsschule Winterthur) https://www.bbw.ch)
/* Autor: ph. gressly */
/* Datum: 8. Nov. 2011 */
/* Erzeuge ein Schachbrettmuster. */
#include <stdio.h>
/**
* Hauptprogramm:
* Erzeuge die Nummerierung eines Schachbrettmusters.
*/
main() {
int spalte;
char zeile = 'H';
while(zeile >= 'A') {
spalte = 1;
while(spalte <= 8) {
printf("%c%i ", zeile, spalte);
spalte = spalte + 1;
}
zeile = zeile - 1;
printf("\n");
}
}
Lösung von: Philipp G. Freimann (BBW (Berufsbildungsschule Winterthur) https://www.bbw.ch)
/**
* Programmieraufgaben.CH
*
* date : 2011-10-15
* author: philipp gressly freimann (Santis Training AG)
* PL/1: www.iron-spring.com
*/
Schach:
procedure options(main);
declare
zeile char(1) init('H'),
spalte fixed(7) ;
/* Start Schleife */
do while(zeile >= 'A');
spalte = 1;
do while(spalte < 9);
put edit(zeile)(a(1));
put edit(spalte)(f(1));
put edit(' ')(a(1));
spalte = spalte + 1;
end;
put skip list('');
/* Konvertiere in Zahl, zähle Eins ab, danach zurück in Char: */
zeile = BYTE(RANK(zeile) - 1);
end;
end Schach;
Lösung von: Philipp G. Freimann (BBW (Berufsbildungsschule Winterthur) https://www.bbw.ch)
/**
* Programmieraufgaben.CH
*
* date : 2011-10-15
* author: philipp gressly freimann (Santis Training AG)
* PL/1: www.iron-spring.com
*/
Schach:
procedure options(main);
declare
colla char(256);
colla = COLLATE();
declare
zeile char(1) init("H"), /* H .. A */
spalte fixed(7) ; /* 1 .. 8 */
/* Start Schleife */
do while(zeile >= 'A');
spalte = 1;
do while(spalte < 9);
put edit(zeile)(a(1));
put edit(spalte)(f(1));
put edit(' ')(a(1));
spalte = spalte + 1;
end;
/* Neue Zeile: */
put skip list('');
/* Konvertiere in Zahl, zähle Eins ab, danach zurück in Char: */
/* zeile = BYTE(RANK(zeile) - 1); */
/* Dies geht auch ohne "BYTE()" und "RANK()" */
zeile = SUBSTR(colla, INDEX(colla, zeile) - 1, 1); /* 1. Zeichen des Substrings.*/
end;
end Schach;
Lösung von: Philipp G. Freimann (BBW (Berufsbildungsschule Winterthur) https://www.bbw.ch)
/*
* http://www.programmieraufgaben.ch
* Aufgabe: Schachbrett
* Autor : Bruno Keller (http://www.santis-training.ch)
* Date : 13. Nov. 2011
*/
Schach: proc options(main);
dcl (Zeile, Spalte) char(1);
do Zeile = 'H','G','F','E','D','C','B','A';
do Spalte = '1','2','3','4','5','6','7','8';
put edit(Zeile, Spalte, ' ')(a(1), a(1), a(1));
end;
put skip list('');
end;
end Schach;
Lösung von: Bruno Keller (Santis Training AG)
// Haskell / List comprehensions
// Diese Programm hat leider keine allzu schöne Ausgabe.
[[(b, n) | n <- [1..8]] | b <- ['H','G'..'A']]
Lösung von: Reto Hablützel (www.rethab.ch)
a,b,u,l=1,7,64,map(chr,range(65,73))
for i in xrange(u):
print letters[b]+str(a),
a+=1
if a==9:
a=1
b-=a
print ''
Lösung von: Oguzhan Yigit (Wilhelm-Maybach Schule Profil: Informatik)
S = "HGFEDCBA"
N = 8
#VERSION 1
for s in S:
print "";
for n in enumerate(S):
print "%s%d" %(s, n[0] + 1),
print "";
print
#VERSION 2
for i in xrange(N):
print "";
for n in xrange(N):
print "%s%d" %(chr(72 - i), n + 1),
print "";
print
#VERSION 3
for i, chess_field in enumerate(((s + str(d[0] + 1)) for s in S
for d in enumerate(S))):
print chess_field,
if i %(len(S)) == len(S) - 1:
print;
print "";
print
#VERSION 4
for i, chess_field in enumerate((n + (str(s + 1)) for n in map(
chr, xrange(65 + N, 65)) for s in xrange(N))):
print chess_field,
if i %(N) == N - 1:
print;
Lösung von: Name nicht veröffentlicht
class cChess {
private $chars;
private $charsReverse;
private $chess;
/**
*
* Erstelle das Schachbrett
* @return $chess string das Schachbrett
*/
public function _getChess() {
// Array mit Buchstaben erstellen
$this->chars = array('A','B','C','D','E', 'F', 'G', 'H');
// Array Werte umdrehen
$this->charsReverse = array_reverse($this->chars);
// Durchlaufe das Array in Umgekehrter Reihenfolge
foreach ( $this->charsReverse as $char ) {
// Wiederhole solange $x kleiner gleich 8 ist
for ( $x=1; $x <= 8; $x++ ) {
$this->chess .= $char . $x . ' ';
// Ist die Schleife durchgelaufe?
if($x == 8 ) {
// Die Werte umbrechen z.b. nach H8 <br />
$this->chess .= "<br />";
}
}
}
return $this->chess;
}
}
$objChess = new cChess();
echo $objChess->_getChess();
Lösung von: Name nicht veröffentlicht
#Python 3
buchstaben=['A','B','C','D','E','F','G','H']
nummern = range(8, 0, -1)
for z in nummern:
for b in buchstaben:
print(b,z,sep='',end=' ')
print('\n')
Lösung von: Claude Vonlanthen (Kantonsschule Olten)
static void Main(string[] args)
{
for (int i = 8; i > 0; --i)
{
for (int j = 65; j <= 72; ++j)
Console.Write(String.Format("{0}{1} ", (char)j, i));
Console.WriteLine();
}
Console.ReadLine();
}
Lösung von: Luca Welker (SBS Software GmbH)
import sys
buchst = ["A","B","C","D","E","F","G","H"]
zahl = ["1","2","3","4","5","6","7","8"]
for i in buchst:
for y in zahl:
sys.stdout.write(i)
sys.stdout.write(y + " ")
sys.stdout.write("\n")
Lösung von: Py Thon ()
static void Main(string[] args)
{
string[] buchstabe = new String[]
{
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H"
};
for (int x = 8; x > 0; --x)
{
for (int i = 0; i < 8; i++)
{
Console.Write(buchstabe[i] + (x) + " ");
}
Console.WriteLine();
}
Console.ReadKey();
}
//http://www.khanacademy.org/cs/new
var buchstaben = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'];
var b ; // Buchstabenindex
var z ; // Ziffer
var x ; // X-Position des Textes
var y ; // Y-Position
fill(0,0,0);
y = 10;
for(z = 8; z > 0; z = z - 1) {
x = 10;
for(b = 0; b < 8; b = b + 1) {
text(buchstaben[b]+""+z, x, y);
x = x + 25;
}
y = y + 20;
}
Lösung von: Philipp G. Freimann (BBW (Berufsbildungsschule Winterthur) https://www.bbw.ch)
public class SchachbrettAusgabe
{
//Gibt folgende Ausgabe aus:
//A8 B8 C8 D8 E8 F8 G8 H8
//A7 B7 C7 D7 E7 F7 G7 H7
//A6 B6 C6 D6 E6 F6 G6 H6
//A5 B5 C5 D5 E5 F5 G5 H5
//A4 B4 C4 D4 E4 F4 G4 H4
//A3 B3 C3 D3 E3 F3 G3 H3
//A2 B2 C2 D2 E2 F2 G2 H2
//A1 B1 C1 D1 E1 F1 G1 H1
public static void main(String[] args)
{
char letter = 'A';
while(letter <= 'H')
{
char number = '8';
while(number >= '1')
{
System.out.print("" + letter+ number+ " ");
number = (char) (number- 1);
}
System.out.println();
letter = (char) (letter+ 1);
}
}
}
Lösung von: Marc We (Marc1706 (11 Jahre alt :D))
/**
* Screenshot kann man hier sehen:
* http://chmu.bplaced.net/?p=472
*
* @author Christoph Müller
*
*/
public class Schachbrett extends JPanel {
private static final long serialVersionUID = 8867677182255515759L;
private final int breiteFeld = 40;
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
boolean feldSchwarz;
for (int i = 0; i < 8; i++) {
if (i % 2 == 0) {
feldSchwarz = false;
} else {
feldSchwarz = true;
}
for (int j = 0; j < 8; j++) {
// Farbe für Schachbrett setzen
if (feldSchwarz) {
g.setColor(Color.BLACK);
} else {
g.setColor(Color.WHITE);
}
// Schachmuster zeichnen
g.fillRect(i * breiteFeld, j * breiteFeld, breiteFeld, breiteFeld);
// Farbe für Beschriftung setzen
if (feldSchwarz) {
g.setColor(Color.WHITE);
} else {
g.setColor(Color.BLACK);
}
// Beschriftungen setzen
g.drawString((char) (65 + i) + "" + (8 - j), i * breiteFeld + 10, j * breiteFeld + 25);
feldSchwarz = !feldSchwarz;
}
}
}
public static void main(String[] args) {
JFrame frame = new JFrame("Schachbrett");
frame.setSize(340, 360);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
int x = (d.width - frame.getSize().width) / 2;
int y = (d.height - frame.getSize().height) / 2;
frame.setLocation(x, y);
frame.add(new Schachbrett());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Lösung von: Christoph Müller ()
// Autor: Andy Großhennig
// Solution for task: Schachbrett (Schleifen)
#include <iostream>
using namespace std;
void chess()
{
char c_arrChessLetters[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'};
char c_arrChessNumbers[] = {'1', '2', '3', '4', '5', '6', '7', '8'};
short shLetter = 0;
short shNumber = 7;
while(shLetter <= 7 && shNumber >= 0)
{
while(shLetter <= 7)
{
cout << c_arrChessLetters[shLetter] << c_arrChessNumbers[shNumber] << " ";
shLetter++;
}
cout << endl << endl;
shLetter = 0;
shNumber--;
}
}
int main()
{
chess();
cout << "\n\n";
system("Pause");
return 0;
}
Lösung von: Andy Großhennig (Bundeswehr)
@let=(A, B, C, D, E, F, G, H);
for($i=7; $i >= 0; $i--){
for($y=1; $y <=8; $y++){
print "$let[$i]$y ";
}
print "\n";
}
Lösung von: Name nicht veröffentlicht
#include <stdio.h>
#include <conio.h>
using namespace std;
int main() {
char zeile = 'A';
int zahl = 8;
for (int i = 1; i <= 8 ; zeile++) {
printf("%c", zeile);
printf("%i", zahl);
printf("%s", " ");
if (zeile == 'H') {
printf("\n\n");
zahl--;
zeile = 'A' - 1;
i++;
}
}
getch();
return 0;
}
Lösung von: Name nicht veröffentlicht
buchstaben = ('A','B','C','D','E','F','G','H')
print([(str(i)+str(s)) for i in range(8,0,-1) for s in buchstaben])
Lösung von: Viktor Reib ()
Function SchachbrettAnzeige()
SchachbrettAnzeige = False
Dim zähler As Integer
Dim BuchstabenNummer As Integer = 65 'ASCII-Code
Dim ausgabe As String
Dim zähler2 As Integer
For zähler2 = 8 To 1 Step -1
BuchstabenNummer = 65
For zähler = 1 To 8
ausgabe = ausgabe & Chr(BuchstabenNummer) & zähler2 & " "
BuchstabenNummer = BuchstabenNummer + 1
Next
ausgabe = ausgabe & vbCrLf
Next
txtSchachbrett.Text = vbCrLf & ausgabe
SchachbrettAnzeige = True
End Function
Lösung von: Johannes vh ()
program Schachbrett (input, output);
{ gibt die Numerierung eines Schachbrettes aus }
const
GROESSE = 8;
type
tIndex = 1..GROESSE;
tBuchstaben = 'A'..'H';
var
i,
j: tIndex;
Buchstaben: array[tIndex] of tBuchstaben;
begin
{ Initialisieren }
for i := 1 to GROESSE do
Buchstaben[i] := char(64+i);
{ ausgeben }
for i := GROESSE downto 1 do
begin
for j := 1 to GROESSE do
write(' ', Buchstaben[j], i);
writeln;
end;
end. { Schachbrett }
Lösung von: Patrick Reif ()
array1=(A B C D E F G H) array2=(1 2 3 4 5 6 7 8)
typeset -i i=7 j=0
string=""
while ((i >= 0))
do
while ((j <= 7))
do
string=${string}${array1[$i]}${array2[$j]}" "
j=j+1
done
j=0
i=i-1
echo $string
string=""
done
Lösung von: Benny H. ()
// Programmiersprache: Go
package main
import "fmt"
var arr = []string{"A", "B", "C", "D", "E", "F", "G", "H"}
func main() {
for j := 8; j > 0; j-- {
for _, c := range arr {
fmt.Printf("%s%d ", c, j)
}
fmt.Printf("\n")
}
}
Lösung von: Matthias Sayler (Bosch)
package programmieraufgaben;
public class Chessboard {
public static void main(String[] args) {
char letter = 'A';
int number = 8;
for (number = 8; number > 0; number--) {
for (int i = 0; i < 8; i++) {
System.out.print(letter + "" + number + " ");
letter++;
}
System.out.print("\n");
letter = 'A';
}
}
}
Lösung von: Ira Darkness ()
puts "Ausgabe eines Schachbrettmusters:"
numbers = (1..8).to_a.reverse
letters = ("A".."H").to_a
numbers.each do |i|
letters.each do |j|
if j != "H"
print "#{j}#{i} "
else
print "#{j}#{i}\n"
end
end
end
Lösung von: Name nicht veröffentlicht
#!/usr/bin/env perl
#use Modern::Perl;
print "Bitte Zahl eingeben, bei der geprüft werden soll, ob es sich um eine Zweierpotenz handelt: ";
my $input = <STDIN>;
my $pow2 = 1;
my $bool = 1;
while ($input >= $pow2) {
if ($input == $pow2) {
print "TRUE\n";
$bool = 0;
last;
}
else {
$pow2 = $pow2 * 2;
}
}
if ($bool == 1) {
print "FALSE\n";
}
Lösung von: Patricia Beier ()
//F#
let brett =
[for c in [72..-1..65]
-> [for n in [8..-1..1]
-> ((char c) |> string) + (n |> string)]]
Lösung von: Vural Acar ()
use strict;
use warnings;
use diagnostics;
use 5.010;
use utf8;
INIT {
# Defining variables
my @letters = qw{A B C D E F G H};
my @numbers = qw{8 7 6 5 4 3 2 1};
foreach my $number (@numbers) {
foreach my $letter (@letters) {
print $letter.$number." ";
}
print "\n";
}
print "Press key to end...\n";
system("pause.exe >nul");
exit;
}
Lösung von: Name nicht veröffentlicht
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
int main()
{
for(int i = 8; i > 0; i -= 1) {
for(char c = 'A'; c < 'I'; c += 1) {
printf("%c%i ", c, i);
}
printf("\n");
}
getchar();
return 0;
}
Lösung von: Elias Zech (Optics Balzers)
<!--Diese Lösung ist eigentlich für Coldfusion gedacht-->
<!--Nur steht diese Sprache leider nicht zur Auswahl zur Verfügung-->
<cfoutput>
<cfset char_array = ['A', 'B', 'C', 'D', 'E', 'F','G','H']>
<cfloop from="8" to="1" index="i" step="-1">
<cfloop from="1" to="#arrayLen(char_array)#" index="y">
#char_array[y]##i#
</cfloop>
<br>
</cfloop>
</cfoutput>
Lösung von: Daniela Hi. ()
#!/usr/bin/perl -w
use strict;
use warnings;
my @letters = ("A".."H");
for ( my $i = 8; $i >= 1; $i-- ) {
foreach my $letter ( @letter ) {
print $letter . $i . " ";
}
print "\n";
}
Lösung von: Mister iC ()
for (var x = 8; x >=1; x--) {
for (var y = 97; y <= 104; y++)
document.write(String.fromCharCode(y) + x + " ");
document.write("<br>");
}
Lösung von: Lisa Salander (Heidi-Klum-Gymnasium Bottrop)
<?php
for($i = 8; $i > 0; $i--){
for($j = 65; $j <= 73; $j++){
echo chr($j). $i. ' ';
}
echo '<br>';
}
Lösung von: Julian Mueller (BSZ Würzburg)
#include <stdio.h>
/*
Schreiben Sie ein Programm, das die Nummerierung eines Schachbretts in der folgenden Form ausgibt:
A8 B8 C8 D8 E8 F8 G8 H8
A7 B7 C7 D7 E7 F7 G7 H7
A6 B6 C6 D6 E6 F6 G6 H6
A5 B5 C5 D5 E5 F5 G5 H5
A4 B4 C4 D4 E4 F4 G4 H4
A3 B3 C3 D3 E3 F3 G3 H3
A2 B2 C2 D2 E2 F2 G2 H2
A1 B1 C1 D1 E1 F1 G1 H1
*/
int main(void)
{
int j;
char c;
for(j = 8; j > 0; j--)
{
for(c = 'A'; c < 'I'; c++)
printf("%c%i ", c, j);
printf("\n");
}
getchar();
return 0;
}
Lösung von: Name nicht veröffentlicht
package ch.FastByte22.Programmieraufgaben;
/**
*
* @author Sam und David
*
*/
public class Schachbrett {
public static void main(String[]args) {
for(int zaehler=8;zaehler>=1;zaehler--) {
for(int buchstabe=65;buchstabe<=72;buchstabe++) {
System.out.print(((char)buchstabe)+""+zaehler+" ");
}
System.out.println("");
}
}
}
Lösung von: David Wu (Gut-genug.com)
for x in [' '.join([chr(b)+str(z) for b in range(65,73)]) for z in range(8,0,-1)] : print(x)
Lösung von: rob ert (tub)
// Example program
#include <iostream>
#include <string>
using namespace std;
int main()
{
//Zeichen Array
char zeichen[] ={'A','B','C','D','E','F','G','H'};
//Loop mit 8 Durchläufen
for(int durchlauf=8;durchlauf >0;durchlauf--){
//weiterer Loop ruft array Elemente auf
for(int spalte = 0; spalte<=7;spalte++){
//Ausgabe vom Durchlauf und des Elements
cout<<durchlauf<<zeichen[spalte]<<"\t";
}
cout<<endl;
}
}
Lösung von: Yannick .. (It-Handbook.net)
public class Schachbrett {
public static void main(String[] args) {
for (int i = 8; i >= 1; i--) {
for (char c = 'A'; c <= 'H'; c++) {
System.out.print(c + "" + i + " ");
}
System.out.println();
}
}
}
Lösung von: Name nicht veröffentlicht
%Matlab
A = {'1','2','3','4','5','6','7','8'}
B = {'H', 'G', 'F', 'E', 'D', 'C', 'B', 'A'}
for b = 1 : length(B)
for a = 1 : length(A)
fprintf('%s%s ',B{b},A{a})
end
fprintf('\n')
end
Lösung von: rob ert (tub)
#!/bin/bash
for z in 8 7 6 5 4 3 2 1 ; do
for b in A B C D E F G H ; do
echo -n $b$z' '
done
echo
done
Lösung von: rob ert (tub)
'5.3.2017 - PowerBASIC 10
#COMPILE EXE
#DIM ALL
FUNCTION PBMAIN () AS LONG
DIM i AS INTEGER
DIM x AS INTEGER
DIM Schachbrett AS STRING
FOR i = 8 TO 1 STEP -1
FOR x = 65 TO 72
Schachbrett += CHR$(x) & FORMAT$(i) & CHR$(32)
NEXT x
Schachbrett += $CRLF
NEXT i
MSGBOX Schachbrett,,EXE.NAME$
END FUNCTION
Lösung von: Markus Sägesser (keine)
#!/usr/local/bin/perl
$i=7;@v=(A..H);@y=(1..8);foreach$a(@v{$p=join("$v[$i]",@y)print"@v[$i]"."$p\n";$i--;}
#eine besonders "schöne" Lösung
Lösung von: Der Azubi (Imperium)
#!/usr/bin/python3.6
start_char = 'A'
end_char = 'H'
char_array = []
for i in range(ord(start_char), ord(end_char)+1):
char_array.append(chr(i))
rows = []
for i in range(0, len(char_array)):
row = ''
for char in char_array:
row = row + f"{char}{len(char_array)-i} "
rows.append(row.strip())
for row in rows:
print(row)
Lösung von: Name nicht veröffentlicht
#include <stdio.h>
#include <string.h>
int main()
{
char buch [] = {'A','B','C','D','F','G','H'};
int j;
int i;
for(j=0;j<7;j++){
{
for(i=8;i>=1;i--)
{
printf("%c%i ",buch[j],i);
}
}
printf("\n");
}
Lösung von: Name nicht veröffentlicht
anzahlReihen = 8
anzahlLinien = 8
schachbrett = [[0] * anzahlReihen for i in range(anzahlLinien)]
for reihe in range(anzahlReihen):
for linie in range(anzahlLinien):
schachbrett[reihe][linie] = chr(65+linie) + str(reihe+1)
for row in schachbrett[::-1]:
print(' '.join([str(element) for element in row]))
Lösung von: Peter Pan (Home Office)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Schachbrett
{
class Program
{
static void Main(string[] args)
{
// Entweder so...
for (int i = 8; i >= 1; i--)
{
for (int j = 65; j <= 72; j++)
{
Console.Write("{0}{1} ", (char)j, i);
if (j == 72)
{
Console.WriteLine();
break;
}
}
}
Console.WriteLine();
//...oder so
for (int i = 72; i >= 65; i--)
{
for (int j = 1; j <= 8; j++)
{
Console.Write("{0}{1} ", (char)i, j);
if (j == 8)
{
Console.WriteLine();
break;
}
}
}
Console.ReadKey();
}
}
}
Lösung von: Chrischi Leif (S&N Datentechnik)
from string import ascii_uppercase
def schachbrett():
for num in range(8, 0, -1):
for char in ascii_uppercase[:8]:
print(char + str(num) + " ", end="")
print("")
Lösung von: marcus -- ()
//Programmiersprache: RUST
fn main() {
for number in (0..=8).rev() {
for char in 'A'..='H' {
print!("{}{} ", char, number);
}
println!("");
}
}
Lösung von: Name nicht veröffentlicht
// NET 6.0 | C# 10.x | VS-2022
var i = 0;
while (i < 64) Console.Write($"{(char)(i % 8 + 'A')}{8 - i++ / 8}{(i % 8 == 0 ? "\n" : " ")}");
Lösung von: Jens Kelm (@JKooP)
#include <iostream>
using namespace std;
int main(){
/* alt. Lösung
for(char x = 65; x < 73; x++) {
for(int i = 1; i < 9; i++) {
cout << x << i << " ";
if(i == 8)
cout << "\n";
}
}
*/
for(char x = 72; x > 64; x--) {
for(int i = 1; i < 9; i++) {
cout << x << i << " ";
if(i == 8){
cout << "\n";
}
}
}
}
Lösung von: Name nicht veröffentlicht
static void Main(string[] args)
{
/* ursprüngliche Aufgabenstellung
for (byte i = 65; i < 73; i++) {
for (byte b = 1; b < 9; b++) {
Console.Write("{0}{1} {2}", (char)i, b, b > 7 ? "\n" : "");
if (b > 7)
break;
}
}
*/
for (byte i = 72; i > 64; i--) {
for (byte b = 1; b < 9; b++) {
Console.Write("{0}{1} {2}", (char)i, b, b > 7 ? "\n" : "");
if (b > 7)
break;
}
}
Console.ReadKey(); // endl
}
Lösung von: Name nicht veröffentlicht
// Programmiersprache: Go
// https://go.dev/
package main
import (
"fmt"
)
func main() {
for num := 8; num > 0; num-- {
for char := 'A'; char <= 'H'; char++ {
fmt.Printf("%c%d ", char, num)
}
fmt.Println()
}
}
Lösung von: Max Mnemo ((mnemo.uk))
// NET 6.x | C# 10.x | VS-2022
Enumerable.Range(1, 8).Reverse()
.Select(x => string.Join(" ", Enumerable.Range('A', 8)
.Select(y => $"{(char)y}{x}"))).ToList()
.ForEach(Console.WriteLine);
Lösung von: Jens Kelm (@JKooP)
// C++ 14 | VS-2022
#include <iostream>
int main() {
for (size_t i{ 0 }; i < 64;) {
auto a{ (char)(i % 8 + 'A') };
auto b{ 8 - i++ / 8 };
auto c{ (!(i % 8) ? "\n" : " ") };
std::cout << a << b << c;
}
}
Lösung von: Jens Kelm (@JKooP)
Aktionen
Neue Lösung hinzufügen
Bewertung
Durchschnittliche Bewertung:
Meta
Zeit: | 0.25 |
Schwierigkeit: | Leicht |
Webcode: | mxxq-ot2a |
Autor: | Philipp G. Freimann (BBW (Berufsbildungsschule Winterthur) https://www.bbw.ch) |
Kommentare (1)