Cod sursa(job #2196089)

Utilizator overstainedVlad Radu overstained Data 18 aprilie 2018 13:25:51
Problema Text Scor 100
Compilator java Status done
Runda Arhiva de probleme Marime 0.72 kb
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;

public class Main {
	public static void main(String[] args) throws IOException {
		FileReader in = new FileReader("text.in");
        PrintWriter out = new PrintWriter("text.out");

		int count = 0;
		int totalLength = 0;
		int lengthOfCurrentWord = 0;
		while(in.ready()) {
			char currentChar = (char) in.read();
			if(Character.isAlphabetic(currentChar)) {
				++lengthOfCurrentWord;
			} else {
			    if(lengthOfCurrentWord != 0) {
					++count;
					totalLength += lengthOfCurrentWord;
					lengthOfCurrentWord = 0;
			    }
			}
		}
        out.printf("%d%n", count == 0? 0 : totalLength/count);
		
        in.close();
        out.close();
	}
}