Kod: |
/* * Napišite program koji učitava jednu liniju teksta s najviše * 18455 znakova. Tom tekstu treba izbrisati svaku 3. riječ, a * ostalima izokrenuti redoslijed slova (same riječi ostaju u * originalnom poretku). Tako dobiveni tekst treba ispisati. * Možete pretpostaviti da tekst sadrži samo slova i razmake. * */ #include <stdio.h> #include <stdlib.h> enum { sz = 18456 }; int end; void dumpword(void) { for (;;) { int c = getchar(); if (c==' ') { return; } else if (c=='\n') { end = 1; return; } } } int get(int word[]) { int lc = 0; for (;;) { int c = getchar(); if (c==' ') { return lc; } else if (c=='\n') { end = 1; return lc; } else { word[lc] = c; lc++; } } } void pr(int word[], int lc) { for (lc--; 0<=lc; lc--) { putchar(word[lc]); } putchar(' '); } void exithandle(void) { if (end) { putchar('\n'); exit(0); } } void f(void) { int word[sz]; // Word count. Used for dumping every third word. int wc = 0; for (;;) { if (wc%3 == 2) { dumpword(); exithandle(); wc++; continue; } // Letter count. int lc = get(word); wc++; pr(word, lc); exithandle(); } } int main(void) { f(); return 0; } |
output generated using printer-friendly topic mod. Vremenska zona: GMT + 01:00.