//Задача N1
#include <stdio.h>
long F,P,S,K;
void main(){
FILE *f=fopen("INPUT.TXT","r");
fscanf(f,"%ld%ld",&F,&P);
fclose(f);
S=F;
for(int i=0;i<4;i++){
K=F-1;
while((S-K)%P) K--;
S=(S-K)/P*F+K;
}
f=fopen("OUTPUT.TXT","w");
fprintf(f,"%ld",S);
fclose(f);
}
//Задача N2
#include <stdio.h>
int a,b,c,x,y,z;
void main(){
FILE *f=fopen("OUTPUT.TXT","w");
for(a=0;a<10;a++)
for(b=0;b<10;b++)
for(c=0;c<10;c++){
x=a*1000+c*110+5;
y=1100*c+11*a;
z=11000*b+922;
if(x+y==z) fprintf(f,"%d+%d=%d\n",x,y,z);
}
fclose(f);
}
//Задача N3
#include <stdio.h>
#include <string.h>
char m[1000][31],p[100];
int n=0,i,z[1000],Ok,min=0;
void main(){
FILE *f=fopen("INPUT.TXT","r");
while(fscanf(f,"%*s%s%*s",p)!=EOF){
Ok=1;
for(i=0;i<n;i++)
if(!strcmp(m[i],p)){z[i]++; Ok=0;}
if(Ok){z[n]=1; strcpy(m[n++],p);}
}
fclose(f);
for(i=1;i<n;i++)
if(z[min]>z[i]) min=i;
f=fopen("OUTPUT.TXT","w");
fputs(m[min],f);
fclose(f);
}
//Задача N4
#include <stdio.h>
long a,b,i,z=1;
void main(){
FILE *f=fopen("INPUT.TXT","r");
fscanf(f,"%ld%ld",&a,&b);
fclose(f);
for(i=0;i<b;i++) z=(z*a)%10;
f=fopen("OUTPUT.TXT","w");
fprintf(f,"%ld",z);
fclose(f);
}
//Задача N5
#include <stdio.h>
#include <math.h>
int i,n,k,l;
float x=0,y=0,s=sqrt(0.5);
void main(){
FILE *f=fopen("INPUT.TXT","r");
fscanf(f,"%d",&n);
for(i=0;i<n;i++){
fscanf(f,"%d %d",&k,&l);
switch(k){
case 1: y+=l; break;
case 2: y+=s*l;x+=s*l; break;
case 3: x+=l; break;
case 4: y-=s*l;x+=s*l; break;
case 5: y-=l; break;
case 6: y-=s*l;x-=s*l; break;
case 7: x-=l; break;
case 8: y+=s*l;x-=s*l; break;
}
}
fclose(f);
f=fopen("OUTPUT.TXT","w");
fprintf(f,"%g %g",x,y);
fclose(f);
}
|