• Najnowsze pytania
  • Bez odpowiedzi
  • Zadaj pytanie
  • Kategorie
  • Tagi
  • Zdobyte punkty
  • Ekipa ninja
  • IRC
  • FAQ
  • Regulamin
  • Książki warte uwagi

SPOJ problem NZeC

Object Storage Arubacloud
0 głosów
266 wizyt
pytanie zadane 13 września 2022 w SPOJ przez jarek1725 Nowicjusz (120 p.)

Witam, dostaję błąd NZEC przy próbie wysłania tego kodu:

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int howMuchTimes = sc.nextInt();
        while (howMuchTimes > 0) {
            Scanner sc1 = new Scanner(System.in);

            String testBlackValues = sc1.nextLine();

            String testGreyValues = sc1.nextLine();


            String[] allBlackScannedNumbersList = testBlackValues.split(" ");
            String[] allGreyScannedNumbersList = testGreyValues.split(" ");

            List<Coordinates> scannedBlackCoordinatesList = convertListFromStringsToCoordinates(allBlackScannedNumbersList);
            List<Coordinates> scannedGreyCoordinatesList = convertListFromStringsToCoordinates(allGreyScannedNumbersList);

            List<Integer> listOfResultsFromParenthesesBlack = getListOfResultsFromParentheses(scannedBlackCoordinatesList);
            List<Integer> listOfResultsFromParenthesesGrey = getListOfResultsFromParentheses(scannedGreyCoordinatesList);

            scannedBlackCoordinatesList = addParenthesesResultToEachCoordinate(scannedBlackCoordinatesList, listOfResultsFromParenthesesBlack);
            scannedGreyCoordinatesList = addParenthesesResultToEachCoordinate(scannedGreyCoordinatesList, listOfResultsFromParenthesesGrey);


            float resultOfGaussMethodBlack = getResultOfGaussMethod(scannedBlackCoordinatesList);
            float resultOfGaussMethodGrey = getResultOfGaussMethod(scannedGreyCoordinatesList);

            int result = (int) ((resultOfGaussMethodGrey - resultOfGaussMethodBlack) * 6 + resultOfGaussMethodBlack * 10);

            System.out.println(result);

            howMuchTimes--;
        }

    }


    public static List<Coordinates> convertListFromStringsToCoordinates(String[] stringList) {
        List<Coordinates> scannedCoordinatesList = new ArrayList<>();
        int x = 0;
        int y = 0;

        for (int i = 0; i < (stringList.length - 1); i++) {
            if (i % 2 == 0) {
                x = Integer.parseInt(stringList[i]);
            } else {
                y = Integer.parseInt(stringList[i]);
                scannedCoordinatesList.add(new Coordinates(x, y));
            }
        }

        return scannedCoordinatesList;
    }


    //    Return (Xi+1 – Xi-1)
    public static List<Integer> getListOfResultsFromParentheses(List<Coordinates> numberArray) {
        List<Integer> resultList = new ArrayList<>();

        resultList.add(numberArray.get(1).X - numberArray.get(numberArray.size() - 1).X);

        for (int i = 1; i < numberArray.size() - 1; i++) {
            resultList.add(numberArray.get(i + 1).X - numberArray.get(i - 1).X);
        }

        resultList.add(numberArray.get(0).X - numberArray.get(numberArray.size() - 2).X);

        return resultList;
    }

    public static List<Coordinates> addParenthesesResultToEachCoordinate(List<Coordinates> coordinatesList, List<Integer> parenthesesList) {
        for (int i = 0; i < coordinatesList.size(); i++) {
            coordinatesList.get(i).gaussParenthesesResult = parenthesesList.get(i);
        }
        return coordinatesList;
    }

    public static float getResultOfGaussMethod(List<Coordinates> coordinatesList) {
        float result = 0;
        for (Coordinates coordinate : coordinatesList) {
            result += coordinate.Y * coordinate.gaussParenthesesResult;
        }

        return result / -2;
    }
}

class Coordinates {
    public int X = 0;
    public int Y = 0;
    public int gaussParenthesesResult = 0;

    public Coordinates(int x, int y) {
        X = x;
        Y = y;
    }

    @Override
    public String toString() {
        return "Coordinates{" +
                "X=" + X +
                ", Y=" + Y +
                ", gaussParenthesesResult=" + gaussParenthesesResult +
                "} \n";
    }
}

przy tym zadaniu https://pl.spoj.com/problems/BAJTELEK/

Czy jest to problem z wejściem danych?

komentarz 14 września 2022 przez tmar1212 Bywalec (2,600 p.)
Używałeś debugera? Potrafisz jakoś zawęzić problem?
komentarz 14 września 2022 przez jarek1725 Nowicjusz (120 p.)
Jeśli wpisuje dane po kolei to dostaję dobre outputy, nie wiem dlaczego SPOJ wyrzuca ten błąd i co on oznacza

Zaloguj lub zarejestruj się, aby odpowiedzieć na to pytanie.

Podobne pytania

0 głosów
1 odpowiedź 506 wizyt
pytanie zadane 8 września 2021 w SPOJ przez StonedCodingTom Nowicjusz (150 p.)
+1 głos
2 odpowiedzi 517 wizyt
pytanie zadane 16 sierpnia 2021 w SPOJ przez rtworek Nowicjusz (160 p.)
+1 głos
1 odpowiedź 127 wizyt
pytanie zadane 4 września 2022 w Java przez Aragedens Obywatel (1,120 p.)

92,555 zapytań

141,402 odpowiedzi

319,540 komentarzy

61,938 pasjonatów

Motyw:

Akcja Pajacyk

Pajacyk od wielu lat dożywia dzieci. Pomóż klikając w zielony brzuszek na stronie. Dziękujemy! ♡

Oto polecana książka warta uwagi.
Pełną listę książek znajdziesz tutaj.

Akademia Sekuraka

Kolejna edycja największej imprezy hakerskiej w Polsce, czyli Mega Sekurak Hacking Party odbędzie się już 20 maja 2024r. Z tej okazji mamy dla Was kod: pasjamshp - jeżeli wpiszecie go w koszyku, to wówczas otrzymacie 40% zniżki na bilet w wersji standard!

Więcej informacji na temat imprezy znajdziecie tutaj. Dziękujemy ekipie Sekuraka za taką fajną zniżkę dla wszystkich Pasjonatów!

Akademia Sekuraka

Niedawno wystartował dodruk tej świetnej, rozchwytywanej książki (około 940 stron). Mamy dla Was kod: pasja (wpiszcie go w koszyku), dzięki któremu otrzymujemy 10% zniżki - dziękujemy zaprzyjaźnionej ekipie Sekuraka za taki bonus dla Pasjonatów! Książka to pierwszy tom z serii o ITsec, który łagodnie wprowadzi w świat bezpieczeństwa IT każdą osobę - warto, polecamy!

...