#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
using namespace std;
#define min 3
#define max 15
#define max_case 25
void rand_initialization()
{
srand(time(NULL));
}
char lower_case(int x)
{
char c,d;
int y;
y=0;
if(x<0)
x=0;
if(x>25)
x=25;
for(c='a';c<'z';c++)
{
if(y==x)
{
d=c;break;
}
++y;
}
return d;
}
char upper_case(int x)
{
char c,d;
int y;
y=0;
if(x<0)
x=0;
if(x>25)
x=25;
for(c='A';c<'Z';c++)
{
if(y==x)
{
d=c; break;
}
++y;
}
return d;
}
char which_case(int x)
{
int y;
y=rand()%2;
if(y==0)
return lower_case(x);
else
return upper_case(x);
}
int main(int argc, char** argv)
{
rand_initialization();
char *f1,*f2,*f3;
int *h1,*h2,*h3;
int x,y,z;
int i,j,k;
int sum1,sum2,sum3;
sum1=sum2=sum3=0;
x=min+rand()%max;
y=min+rand()%max;
f1=new char[x];
h1=new int[x];
f2=new char[y];
h2=new int[y];
z=x+y;
f3=new char[z];
h3=new int[z];
for(i=0;i<x;i++)
{
k=rand()%max_case;
f1[i]=which_case(k);
h1[i]=k;
sum1+=h1[i];
f3[i]=f1[i];
h3[i]=h1[i];
}
for(j=0;j<y;j++)
{
k=rand()%max_case;
f2[j]=which_case(k);
h2[j]=k;
sum2+=h2[j];
f3[i+j]=f2[j];
h3[j+i]=h2[j];
}
printf("%s + %s = %s ",f1,f2,f3);
printf("\n");
for(i=0;i<x;i++)
{
cout<<h1[i]<<"+";
}
cout<<" + ";
for(j=0;j<y;j++)
{
cout<<h2[j]<<"+";
}
cout<<" = ";
for(k=0;k<z;k++)
{
cout<<h3[k]<<"+";
sum3+=h3[k];
}
printf("\n");
printf("===============================================================");
printf("\n");
cout<<sum1<<" + "<<sum2<<" = "<<sum3;
delete h3;
delete h2;
delete h1;
delete f3;
delete f2;
delete f1;
return 0;
}
Brak komentarzy:
Prześlij komentarz