Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package matura2k18;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.util.Scanner;
- public class Matura {
- public static void main(String[] args) {
- System.out.println("Matura");
- String message = getMessage_4_1();
- System.out.println( "4.1: " + message);
- get_4_2();
- get_4_3();
- }
- public static char[][] readFile() {
- try {
- Scanner data = new Scanner(new File(".\\Dane_PR2\\przyklad.txt"));
- char[][] tab = new char[1000][];
- int y = 0;
- while (y < 1000) {
- int x = 0;
- String wiersz = data.next();
- tab[y] = new char[wiersz.length()];
- while (x < wiersz.length()) {
- tab[y][x] = wiersz.charAt(x);
- x++;
- }
- y++;
- }
- data.close();
- return tab;
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- public static String getMessage_4_1() {
- char[][] tab = readFile();
- String message = "";
- int y=39;
- while(y<1000) {
- message += tab[y][9];
- y+=40;
- }
- return message;
- }
- public static String get_4_2() {
- char[][] tab = readFile();
- char[] slowoRoznorodneMax = new char [100];
- int roznorodnoscMax = 0;
- int index = -1;
- int y=0;
- while(y<1000) {
- char[] slowo = new char [ tab[y].length ];
- System.arraycopy(tab[y], 0, slowo, 0, tab[y].length);
- int roznorodnosc = 0;
- for( int x=0; x<slowo.length; x++ ) {
- char znak = slowo[x];
- for(int x_2=0; x_2<slowo.length; x_2++) {
- if( znak==' ') {
- znak = '#';
- break;
- }
- if( znak != slowo[x_2] && znak!='#' && znak!=' ') {
- roznorodnosc++;
- break;
- }
- }
- for(int x_2=0; x_2<slowo.length; x_2++) {
- if( znak == slowo[x_2] ) {
- slowo[x_2] = '#';
- }
- }
- if( roznorodnosc > roznorodnoscMax) {
- roznorodnoscMax = roznorodnosc;
- slowoRoznorodneMax = slowo;
- index = y;
- }
- }
- y++;
- }
- String slowoRoznorodneMaxString ="";
- for( int i=0; i<tab[index].length; i++) {
- slowoRoznorodneMaxString += tab[index][i];
- }
- System.out.println("4.2: " + slowoRoznorodneMaxString + " roz="+roznorodnoscMax);
- return slowoRoznorodneMaxString;
- }
- public static void get_4_3() {
- char[][] tab = readFile();
- int y=0;
- while(y<1000) {
- char[] slowo = new char [ tab[y].length ];
- System.arraycopy(tab[y], 0, slowo, 0, tab[y].length);
- boolean czy10Max = true;
- for( int x=0; x<slowo.length; x++ ) {
- char znak = slowo[x];
- for(int x_2=0; x_2<slowo.length; x_2++) {
- int odleglosc = znak - slowo[x_2];
- odleglosc = Math.abs( odleglosc );
- if( odleglosc > 10 ) {
- czy10Max = false;
- break;
- }
- }
- }
- if( czy10Max ) {
- String slowoRoznorodneMaxString ="";
- for( int i=0; i<slowo.length; i++) {
- slowoRoznorodneMaxString += slowo[i];
- }
- System.out.println( slowoRoznorodneMaxString );
- }
- y++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement