Professional Documents
Culture Documents
I N F o R M A T I C S
I N F o R M A T I C S
I N F o R M A T I C S
INFORMATICS
ELEKTRIJADA 2008
Task
1
2
3
4
5
6
7
8
9
10
TOTAL
Points
#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]);
}
#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:
#include <stdio.h>
int j, total;
#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;
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);
}
#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:
#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:
#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:
#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:
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.