I N F o R M A T I C S

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

ELEKTRIJADA 2008

Banja Vruica, May 19-24.2008.

INFORMATICS
ELEKTRIJADA 2008

Task
1
2
3
4
5
6
7
8
9
10

TOTAL

Points

ELEKTRIJADA 2008 INFORMATICS, Banja Vruica, May 19-24.2008.

What's the output of the next program?


Put exactly one character in one box, just as will be
displayed on the screen.

#include <stdio.h>
int data[1000], n;
void f(int n) { for ( ; n ; data[n] = n--); }
int g(int s)
{
int i, j, k, b=n;
while(b>1) {
for(i=s; data[i]; data[i]=0, i+=2);
s = (data[i-1]) ? 1 : 2;
for(i=1; i<=b; i++)
if (!data[i]) {
for(j=i; j<b; j++) data[j]=data[j+1];
data[j]=0; b--; }
}
return (data[1]);
}

What's the output of the next program?


Suppose that IEEE 754 standard is used for FP data.

#include <stdio.h>
double f(int i)
{
double data = 1;
while(i--) data/=2; return (data);
}
union unija {double d; float f; char c[8];} u;
main()
{
int i, j, br;
for (br=0, i=126; i<1022; i++)
for (u.f=f(i), j=3; j>=0; j--)
if (u.c[j]) br++; printf("%d", br);
}

Output:

int main()
{
f(n=10); printf("%d\n", g(2));
f(n=100); printf("%d\n", g(1));
}

Output:

What's the output of the next program?

#include <stdio.h>
int j, total;

What's the output of the next program?

#include <stdio.h>
#include <string.h>
#define MAX 10
void rpi(char *u, int *pi)
{
int i=1,j=0,n=strlen(u);
while (i<n)
if (u[j]==u[i]) pi[i++]=++j;
else if (j>0) j=pi[j-1]; else
}

Output:
pi[i++]=0;

int f(char *u, char *t)


{
int i=0,j=0,m,n, pi[MAX];
n=strlen(u); m=strlen(t); rpi(t,pi);
while (i<n)
if (u[j]==t[i])
{ if (j==m-1) return (i-m+1); i++; j++; }
else if (j>0) j=pi[j-1]; else i++;
return (-1);
}
main()
{
char *u="ELEKTRIJADA", t[MAX]="";
int i=0, s=0, n=strlen(u);
for (; i<n; t[0]=*(u+i), s+=f(u,t), i++);
printf("%d", s);
}

Output:

main()
{
int data[10]={0}, k;
for (k=1; k<9; data[k]=data[k-1]+1, k++);
for (; j<10; total+=data[j], j++);
printf("%d\n", total);
for (; k; (k)[data]++, k--);
for (; j; total+=data[--j]);
printf("%d", total);
}

What's the output of the next program?

#include <stdio.h>
char f1 (char *d) { return(++(*d));}
char p1 (void *a) { return (f1((char*)a)); }
main()
{
char d, c='C', *pc=&c;
int i, j, k, *pi=&i;
for (i=3; i; d=p1(pc), i--);
for (j=3; j; k=p1(pi), j--);
printf("%c\n%d", p1(pc), p1(pi));
}

Output:

ELEKTRIJADA 2008 INFORMATICS, Banja Vruica, May 19-24.2008.

What's the output of the next program?

#include <stdio.h>
enum Roman {I,II,III,V=5,IV=4,VI,VII=VI+1};
main()
{
int rom[3][3]={{I,II,III},{IV,V,VI},{VII}};
int i,j,s=0,t=0;
for(i=0; i<2; i++)
for(j=0; j<3; s+=rom[i][j],j++);
for(i=0; i<2; i++)
for(j=0; j<3; t+=*rom[i,j],j++);
printf("%d\n%d", s, t);
}

Output:

What's the output of the next program?

#include <stdio.h>
#define M(X,Y) {x=a+++b; y=X+a; z+=y+b;}
int a, b, x, y, z;
void f(){M(x,y) M(x++,y) M(x,++y) M(x++,y++)}
main() {f(); printf("%d\n%d\n%d", x, y, z);}

Output:

What's the output of the next program?

#include <stdio.h>
int fra(char *s) {
int i, b=0, k, d, n;
for (i=0; s[i]; b+=d, i++)
if ((s[i]-'a')%2)
for(d=5,k=0; k<(s[i]-'1')/2; d*=10,k++);
else {
for(d=1,k=0; k<(s[i]-'1')/2; d*=10,k++);
d *= (s[i+1]-s[i]>2)? -1 : 1;
}
return b;
}
char *fr(int b, char s[]) {
int i, c, k, bcs=0, d=1000;
char sk[11][5]={"","1","11","111","12","2",
"21","211","2111","13","3"};
for (k=6; k>=0; k-=2)
{
for(i=0, c=b/d; sk[c][i]; i++, bcs++)
s[bcs]=sk[c][i]+k;
b%=d; d/=10;
}
s[bcs]=0; return s;
}
main()
{
char s[10], s1[10]="4321", s2[10]="211";
printf("%s\n", fr(fra(s1)/fra(s2),s));
printf("%s", fr(fra(s1)%fra(s2),s));
}

Output:

Consider the next (infix) arithmetic expression:

A+B*C/(D-E)
a) Fill the provided net with the equivalent prefix
expression and then compute the sum of cell
weights (numbers placed bellow the net) of those
cells where operators are placed.

Required sum of cell weights: ????


b) Repeat the previous task for the equivalent postfix
expression and recompute the required sum of
weights for the cells where operators are placed.

Required sum of cell weights: ????


Notes: An equivalent prefix expression (known as Polish
notation) can be obtained by the preorder traversal,
while postfix expression (inverse Polish notation), can
be obtained by the postorder traversal of the
appropriate binary tree.

Two old friends, named Huso and Haso, are


arguing about the performance of their own
algorithms. Huso claims that his O(nlogn)-time
algorithm is faster than Haso's O(n2)-time
algorithm. However, Haso also claims that his
algorithm is faster than Huso's algorithm.
Please, specify correct answer(s):
a) Huso's algorithm is allways faster than
Haso's algorithm.
b) Huso can find appropriate data set and his
algorithm will be faster, but Haso also can
find appropriate data set and show that his
algorithm is faster than Huso's algorithm.
c) Haso's algorithm is allways faster than
Huso's algorithm.
d) Both of algorithms are faster than O(2100)time algorithms in the case of testing array
that doesn't contain more than 100 elements.
e) Haso's algorithm is faster than O(1)-time
algorithms.

You might also like