_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ _ _
Imię i nazwisko Numer indeksu Login (SPOJ)
drukowanymi literami czas pisania: 45 minut
1 grudnia 2009
Zad. 1. Każde z wyróżnionych pól (___) uzupełnij co najwyżej 3 znakami, różnymi od przecinka i średnika, tak aby program po uruchomieniu wypisywał tekst: Hello (6 pkt.)
#include <stdio.h>
int main (){
int t[] = {'H', 'e', 'l', `l', `H', `o', `e', 0, `l', 'l', 'o'};
for ( int i=1; t[i+3]; i+=2, i%=7)
printf ("%c", t[i+3]);
}
Zad. 2. Jaki tekst zostanie wypisany przez poniższy program? (4 pkt.)
Wynik: Nhellollo-worldssible
#include <stdio.h>
void weird_string_copy(char *s, char *d) {
while (*d) *++s = *d++;
}
int main() {
char s1[100] = "Nothing-is-impossible";
char s2[] = "Hello-world";
weird_string_copy (s1, s2);
weird_string_copy (s1+5, &s2[2]);
printf ("%s", s1);
}
Zad. 3. Obok każdego wywołania funkcji printf, uzupełnij tekst, który zostanie wypisany. (10 pkt.)
#include <stdio.h>
int main() {
int a=1, b=2, c=3, d=1;
char s[] = {'a','b','c'}, *p = s+1;
printf ("%d", a--* b--); 2
printf ("%d", (c+1) % 3 * 4 / 3); 1
printf ("%d", 2 << 3); 16
printf ("%d", ++c || d--); 1
printf ("%d %d", c, d); 4 1
printf ("%d", 2 ^ 6); 4
printf ("%d", 2 < 7 ? 3 : 4); 3
printf ("%d", 4 == 5); 0
printf ("%c", *(p+1)); c
printf ("%c", *(s)+1); b
printf ("%d", &s[1]==p); 1
}
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ __ _ _ _ _ _ _ _ _ _
Imię i nazwisko Numer indeksu Login (SPOJ)
drukowanymi literami czas pisania: 45 minut
1 grudnia 2009
Zad. 1. Każde z wyróżnionych pól (___) uzupełnij co najwyżej 3 znakami, różnymi od przecinka i średnika, tak aby program po uruchomieniu wypisywał tekst: Hello (6 pkt.)
#include <stdio.h>
int main (){
int t[] = {'H', `o', `l', `H', 0, `l', `e', 'e', 'l', 'l', 'o'};
for ( int i=2; t[i+1]; i+=3, i%=7)
printf ("%c", t[i+1]);
}
Zad. 2. Jaki tekst zostanie wypisany przez poniższy program? (4 pkt.)
Wynik: elloo-worldimpossible
#include <stdio.h>
void weird_string_copy(char *s, char *d) {
while (*++d) *s++ = *d;
}
int main() {
char s1[100] = "Nothing-is-impossible";
char s2[] = "Hello-world";
weird_string_copy (s1, s2);
weird_string_copy (s1+4, &s2[3]);
printf ("%s", s1);
}
Zad. 3. Obok każdego wywołania funkcji printf, uzupełnij tekst, który zostanie wypisany. (10 pkt.)
#include <stdio.h>
int main() {
int a=3, b=2, c=5, d=2;
char s[] = {'x','y','z'}, *p = s+1;
printf ("%d", a--* b--); 6
printf ("%d", (c+1) % 4 * 4 / 3); 2
printf ("%d", 2 << 4); 32
printf ("%d", --c || d++); 1
printf ("%d %d", c, d); 4 2
printf ("%d", 1 ^ 3); 2
printf ("%d", 2 < 7 ? 4 : 3); 4
printf ("%d", 4 == 4); 1
printf ("%c", *(p+1)); z
printf ("%c", *(s)+2); z
printf ("%d", &s[1]==p); 1
}