Miert nem megy at a teszteken ez a feladat megoldas, mar 3verziot probaltam?
Write a program that reads an array of integers and two numbers n and m. The program must check that n and m never occur next to each other (in any order) in the array.
Input data format
The first line contains the size of an array.
The second line contains elements of the array.
The third line contains two integer numbers n and m.
All numbers in the same line are separated by the space character.
Output data format
The result is a single boolean value true if n and m never occur next to each other; otherwise, it is false.
-------------------
Sample Input 1:
3
1 2 3
2 3
Sample Output 1:
false
Sample Input 2:
3
1 2 3
3 4
Sample Output 2:
true
Sample Input 3:
10
3 4 5 6 3 4 6 4 4 8
5 8
Sample Output 3:
true
-------------------------------
ez lenne a megoldasom,de nem megy:
import java.util.Scanner;
class Main {
public static void main(String[] args) {
// put your code here
Scanner scanner = new Scanner(System.in);
// put your code here
int size = scanner.nextInt();
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = scanner.nextInt();
}
int n = scanner.nextInt();
int m = scanner.nextInt();
boolean temp = true;
/*
for(int i = 0; i < array.length; i++ ){
if( array[i] == number[0]){
if( i+1 < array.length ){
if(array[i+1] == number[1]){
temp = false;
}
}
}
}
*/
/*
int temp2 = 0;
for(int i = 0; i < array.length; i++ ) {
if(i>1){
temp2 = array[(i-1)];
}
if ((array[i] == number[1]) && (temp2 == number[0])){
temp = false;
}
}
*/
/*
for(int i = 0; i < array.length; i++ ) {
if(i>1){
temp2 = array[(i-1)];
}
if ((array[i] == m) && (temp2 == n)){
temp = false;
}
}
*/
for(int i = 0; i < array.length; i++ ) {
if ((array[i] == n) && (i+1 < array.length)) {
if(array[i+1] == m){
temp = false;
}
}
}
System.out.println(temp);
}
}
FEEDBACK:
Failed test #5 of 8. Wrong answer





Az output data-nál az van írva, hogy n és m nem fordulhatnak elő egymás mellett.
Ez teljesen egyértelmű, a sorrend lényegtelen.
A leírásba még külön bele is van írva gyengébbek kedvéért.










#13 egy altalanos iskolai szintu feladaton mit oldjak meg? Meg kell nezni, hogy az egymas mellett allo szamparok kozul az egyik egyenlo-e m-mel, a masik meg n-nel. Egy for loop meg egy feltetelvizsgalat az egesz.
Tessek: [link]
Pontozni meg nem szoktam.





További kérdések:
Minden jog fenntartva © 2025, www.gyakorikerdesek.hu
GYIK | Szabályzat | Jogi nyilatkozat | Adatvédelem | Cookie beállítások | WebMinute Kft. | Facebook | Kapcsolat: info(kukac)gyakorikerdesek.hu
Ha kifogással szeretne élni valamely tartalommal kapcsolatban, kérjük jelezze e-mailes elérhetőségünkön!