Schneidbretter (Selektionen)
Frau Koch braucht für ihre Küche neue Schneidebretter. Nun steht sie im Laden und weiß nicht, welche Bretter denn nun in ihre Schublade passen.
Die Schublade misst 45cm x 53cm (Breite x Tiefe). Es stehen verschiedene Bretter zur Auswahl (je Länge x Breite):
- 20 x 30
- 30 x 48
- 50 x 42
- 48 x 48
- 55 x 60
Schreiben Sie nun ein Programm, das von einer Schubladengröße (Breite x Tiefe) und einem Brett (Länge x Breite) angibt, ob das Brett passt. Achtung: Das Brett darf natürilch auch gedreht werden!
(Falls Sie mit ihrer Applikation Erfolg haben, schreiben Sie diese als Smartphone Applikation um, damit Frau Koch auch im Laden ihre Überprüfungen anstellen kann.)
0 Kommentare
17 Lösung(en)
def check(n):
n = n.split("x")
if (int(n[0])>53 or int(n[1])>53) or (int(n[0])>45 and int(n[1])>45) :
return False
return True
print check("43 x 60")
Lösung von: Meritio Bruno ()
public class test {
public static void main(String args[]){
System.out.println(check("46 x 45"));
}
static Boolean check(String s){
String[] n = s.split(" x ");
if ((Integer.parseInt(n[0]) > 53 || Integer.parseInt(n[1])>53) || ((Integer.parseInt(n[0])>45 && Integer.parseInt(n[1])>45)))
return false;
return true;
}
}
Lösung von: Meritio Bruno ()
import java.util.Scanner;
public class Schneidebrett
{
public static void main(String[] args)
{
println("Die Schublade hat die Maße 45x53.");
println("Geben sie Maße der Bretter zum vergleichen ein.");
println("Hinweis: Gleitkommazahlen mit Komma angeben!");
while(true){
Scanner sc = new Scanner (System.in);
boolean check = false;
double first = 0;
double second = 0;
//Schubladenmaß
double laenge = 45;
double breite = 53;
while(check != true)
{
print("\nErste Kantenlänge: ");
first = sc.nextDouble();
print("Zweite Kantenlänge: ");
second = sc.nextDouble();
if (first <= 0)
{
check = false;
println("Eingabefehler. Neustart...");
}
else if (first > 0)
{
if (second <= 0){
check = false;
println("Eingabefehler. Neustart...");}
else if (second > 0){
check = true;}
}
}
if ((first <= laenge && second <= breite) || (first <= breite && second <= laenge)){
println("= BRETT PASST IN DIE SCHUBLADE!!! :)");}
else{println("= BRETT IST ZU GROSS!!! :(");}
}
}
static void print(String a)
{System.out.print(a);}
static void println(String a)
{System.out.println(a);}
}
Lösung von: Marc We (Marc1706 (11 Jahre alt :D))
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
# @autor Philipp Gressly Freimann
# 2011 Feb
# Schneidbretter Programmieraufgaben
def einlesen(wert)
print "Bitte #{wert} eingeben:"
# Dezimalzahl (real) einlesen:
return STDIN.gets.to_f
end
# START
schubladenBreite = einlesen("Breite der Schublade");
schubladenTiefe = einlesen("Tiefe der Schublade");
brettLaenge = einlesen("Länge des Brettes");
brettBreite = einlesen("Breite des Brettes");
if( # normal
(schubladenBreite >= brettBreite &&
schubladenTiefe >= brettLaenge) ||
# oder gereht:
(schubladenTiefe >= brettBreite &&
schubladenBreite >= brettLaenge)
)
puts "Es passt."
else
puts "Es Passt leider nicht."
end
Lösung von: Philipp G. Freimann (BBW (Berufsbildungsschule Winterthur) https://www.bbw.ch)
(defun schublade-p (schublade brett)
"T, wenn das Brett in die Schublade passt, sonst NIL."
; Schublade und Brett, werden als Listen mit jeweils zwei Elementen übergeben.
(every #'(lambda (x) x) (mapcar #'>= (sort schublade #'<) (sort brett #'<))))
Lösung von: Stefan Meichtry (Erwachsenenbildung)
// Autor: Andy Großhennig
// Solution for task: Schneidbretter (Selektionen)
#include <iostream>
using namespace std;
// Function: Compare the planks with the maximum size
// and show if the plank is tall enough
void checkSize()
{
const short so_arrMaxSize[2] = {45, 53};
const short so_arrPlanks[5][2] = {{20, 30},
{30, 48},
{50, 42},
{48, 48},
{55, 60}};
for(int i = 0;i < sizeof so_arrPlanks / sizeof so_arrPlanks[0];i++)
{
if(so_arrMaxSize[0] > so_arrPlanks[i][0] && so_arrMaxSize[1] > so_arrPlanks[i][1])
{
cout << "Das Brett Nummer " << (i + 1) << " passt in die Schublade\n";
}
else if(so_arrMaxSize[0] > so_arrPlanks[i][1] && so_arrMaxSize[1] > so_arrPlanks[i][0])
{
cout << "Das Brett Nummer " << (i + 1) << " passt in die Schublade\n";
}
}
}
int main()
{
checkSize();
cout << "\n\n";
system("Pause");
return 0;
}
Lösung von: Andy Großhennig (Bundeswehr)
// Autor: Andy Großhennig
// Solution for task: Schneidbretter (Selektionen) - With user input
#include <iostream>
using namespace std;
// Function: Compare the input of the size with the maximum size
// and show whether the plank is tall enough
void checkSize()
{
const short so_arrMaxSize[2] = {45, 53};
short so_arrPlank[2];
cout << "Geben sie die Laenge des Brettes ein: ";
cin >> so_arrPlank[0];
cout << "\nGeben sie die Breite des Brettes ein: ";
cin >> so_arrPlank[1];
cout << endl;
if(so_arrMaxSize[0] > so_arrPlank[0] && so_arrMaxSize[1] > so_arrPlank[0])
{
cout << "Das Brett passt in die Schublade\n";
}
else if(so_arrMaxSize[0] > so_arrPlank[1] && so_arrMaxSize[1] > so_arrPlank[0])
{
cout << "Das Brett passt in die Schublade\n";
}
else cout << "Das Brett passt nicht in die Schublade\n";
cout << endl;
}
int main()
{
char chOption;
checkSize();
cout << "Wollen sie ein weiteres Brett testen? j/n ";
cin >> chOption;
cout << endl;
while (chOption == 'j')
{
checkSize();
cout << "Wollen sie ein weiteres Brett testen? j/n ";
cin >> chOption;
cout << endl;
}
cout << "\n\n";
system("Pause");
return 0;
}
Lösung von: Andy Großhennig (Bundeswehr)
'autor Patrick Prem
Public Class Schneidbretter
Private Sub Schneidbretter_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub cmdprüfen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdprüfen.Click
Dim Schubl As Integer = txtschubl.Text
Dim Schubb As Integer = txtschubb.Text
Dim Länge As Integer = txtlänge.Text
Dim Breite As Integer = txtbreite.Text
If Länge <= Schubl And Breite <= Schubb Then
MsgBox("Es Passt")
ElseIf Breite <= Schubl And Länge <= Schubb Then
MsgBox("Es Passt")
Else
MsgBox("Es passt nicht")
End If
End Sub
End Class
Lösung von: Patrick Prem (Htl Jenbach)
import java.util.Scanner;
public class Schublade {
public static void main(String[] args) {
Scanner länge = new Scanner(System.in);
System.out.println("Bitte geben Sie die Länge an");
int eingabeTiefe = länge.nextInt();
Scanner breite = new Scanner(System.in);
System.out.println("Bitte geben Sie die Breite an");
int eingabeBreite = breite.nextInt();
if (eingabeBreite <=45 && eingabeTiefe <=53){
System.out.println("Das Brett passt in die Schublade!");
}else {
System.out.println("Das Brett passt nicht in die Schublade!");
}
}
}
Lösung von: Kaya kaya ()
var plank = [], drawer = [],
inD = prompt("Maße der Schublade (getrennt durch x):").split("x"),
inP = prompt("Maße des Bretts (getrennt durch x):").split("x"),
i = 0;
for (i; i <= 1; i++) {
plank[i] = parseFloat(inP[i]);
drawer[i] = parseFloat(inD[i]);
}
function fitsIntoDrawer(pl, dr) {
return (
(pl[0] <= dr[0] && pl[1] <= dr[1]) ||
(pl[1] <= dr[0] && pl[0] <= dr[1])
);
}
console.log(fitsIntoDrawer(plank, drawer));
Lösung von: Lisa Salander (Heidi-Klum-Gymnasium Bottrop)
import java.util.Scanner;
public class Schneidebretter {
//Schubladengroesse
double BREITE;
double TIEFE;
//Bretter
public final double B1_B = 30;
public final double B1_T = 20;
public final double B2_B = 48;
public final double B2_T = 30;
public final double B3_B = 42;
public final double B3_T = 50;
public final double B4_B = 48;
public final double B4_T = 48;
public final double B5_B = 60;
public final double B5_T = 55;
public void schub() {
Scanner in = new Scanner(System.in);
System.out.println("Breite der Schublade eingeben:");
BREITE = in.nextDouble();
System.out.println("Tiefe der Schublade eingeben: ");
TIEFE = in.nextDouble();
check();
System.out.println("");
}
public void check() {
if(BREITE >= B1_B && TIEFE >= B1_T) {
System.out.println("20 x 30 passt!");
} else {
System.out.println("20 x 30 passt nicht :/");
}
if(BREITE >= B2_B && TIEFE >= B2_T) {
System.out.println("20 x 48 passt!");
} else {
System.out.println("20 x 48 passt nicht :/");
}
if(BREITE >= B3_B && TIEFE >= B3_T) {
System.out.println("50 x 42 passt!");
} else {
System.out.println("50 x 42 passt nicht :/");
}
if(BREITE >= B4_B && TIEFE >= B4_T) {
System.out.println("48 x 48 passt!");
} else {
System.out.println("48 x 48 passt nicht :/");
}
if(BREITE >= B5_B && TIEFE >= B5_T) {
System.out.println("55 x 60 passt!");
} else {
System.out.println("55 x 60 passt nicht :/");
}
}
public static void main(String[] args) {
new Schneidebretter().schub();
}
}
Lösung von: Name nicht veröffentlicht
import java.util.Scanner;
public class Schneidbretter {
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
String result;
System.out.println("Bitte gebe die Länge des Schneidebrettes ein:");
int tiefe = sc.nextInt();
System.out.println("Bitte gebe die Breite des Schneidebrettes ein:");
int breite = sc.nextInt();
if (breite <= 45 && tiefe <= 53) {
result = ("Das Brett passt nicht in die Schublade");
}
if (tiefe <= 45 && breite <= 53) {
result = ("Das Brett passt in die Schublade");
} else {
result = ("Das Brett passt nicht in die Schublade");
}
System.out.println(result);
}
}
Lösung von: Raphael Bosshart (ETH ZH)
schublade = (45, 53)
bretter = [(20, 30), (30, 48), (50, 42), (48, 48), (55, 60)]
eingabe = int(input("Welches Brett (1 - 5) wählen Sie? "))
if min(bretter[eingabe - 1]) <= min(schublade) and max(bretter[eingabe - 1]) <= max(schublade):
print("Brett", eingabe, "passt!")
else:
print("Brett", eingabe, "passt leider nicht!")
Lösung von: Peter Pan (Home Office)
// NET 6.x | C# 10.x | VS-2022
var lstBretter = new List<(int bB, int bT)> { (20, 30), (30, 48), (50, 42), (48, 48), (55, 60), (53, 45) };
var (sB, sT) = (45, 53); // Schublade
lstBretter.ForEach(x => Console.WriteLine($"{x} -> passt {(Math.Min(x.bB, x.bT) <= sB && Math.Max(x.bB, x.bT) <= sT ? "" : "nicht")}"));
Lösung von: Jens Kelm (@JKooP)
// C++ 17
#include <iostream>
#include <vector>
struct Size {
int length;
int width;
};
int main() {
std::vector<Size> cutting_boards{ { 20, 30 }, { 30, 48 }, { 50, 42 }, { 48, 48 }, { 55, 60 }, { 53, 45 } };
Size drawer{ 45, 53 };
for (const auto& cb : cutting_boards) {
const auto& min{ std::min(cb.width, cb.length) };
std::cout << cb.length << " x " << cb.width << " passt ";
if (!(min <= drawer.width && min <= drawer.length))
std::cout << "nicht";
std::cout << std::endl;
}
}
Lösung von: Jens Kelm (@JKooP)
' VBA
Type Size
Length As Integer
Width As Integer
End Type
Sub Main()
Dim bds(1 To 6) As Size 'cutting boards
bds(1).Length = 20: bds(1).Width = 30
bds(2).Length = 30: bds(2).Width = 48
bds(3).Length = 50: bds(3).Width = 42
bds(4).Length = 48: bds(4).Width = 48
bds(5).Length = 55: bds(5).Width = 60
bds(6).Length = 53: bds(6).Width = 45
Dim drw As Size 'drawer
drw.Length = 45: drw.Width = 53
For i% = LBound(bds) To UBound(bds)
m% = WorksheetFunction.Min(bds(i).Length, bds(i).Width)
s$ = bds(i).Length & " x " & bds(i).Width & " passt"
If Not (m <= drw.Width And m <= drw.Length) Then
s = s & " nicht"
End If
Debug.Print s
Next
End Sub
Lösung von: Jens Kelm (@JKooP)
#include <stdio.h>
#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
typedef struct _DIMENSION_ {
int length;
int width;
}Dimension;
void check_boards(Dimension* cutting_boards, size_t size, Dimension drawer){
for(size_t i = 0; i < size; i++){
int min = MIN(cutting_boards[i].width, cutting_boards[i].length);
printf("%i x %i passt ", cutting_boards[i].length, cutting_boards[i].width);
if(!(min <= drawer.length && min <= drawer.width))
printf("nicht");
printf("\n");
}
}
int main() {
Dimension cutting_boards[] = {
{ 20, 30 }, { 30, 48 }, { 50, 42 },
{ 48, 48 }, { 55, 60 }, { 53, 45 } };
size_t size = sizeof(cutting_boards) / sizeof(cutting_boards[0]);
Dimension drawer = { 45, 53 };
check_boards(cutting_boards, size, drawer);
}
Lösung von: Jens Kelm (@JKooP)
Verifikation/Checksumme:
Gegeben Schublade (Breite x Tiefe): 17 x 24
Passend: 17x17, 17x18, 18x17, 24x16 und 16x24
Unpassend: 18x18, 16x25
Aktionen
Neue Lösung hinzufügen
Bewertung
Durchschnittliche Bewertung:
Meta
Zeit: | 0.25 |
Schwierigkeit: | Mittel |
Webcode: | a8nn-9r92 |
Autor: | Philipp G. Freimann (BBW (Berufsbildungsschule Winterthur) https://www.bbw.ch) |