Created
December 15, 2013 14:16
-
-
Save goloveychuk/7973535 to your computer and use it in GitHub Desktop.
8-9 lab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <time.h> | |
#include <iomanip> | |
#include <conio.h> | |
using namespace std; | |
bool flag; | |
void random(int **a,int n1,int n2)//filling massive of random numbers | |
{ | |
for (int n=0;n<n1;n++) | |
for (int k=0;k<n2;k++) | |
a[n][k]=rand()%100; | |
} | |
void input(int **a,int n1,int n2)//filling massive manually | |
{ | |
for (int n=0;n<n1;n++) | |
for (int k=0;k<n2;k++) | |
{ | |
cout<<"a["<<n<<"]["<<k<<"]="; | |
cin>>a[n][k]; | |
} | |
} | |
void outmassive(int **a,int n1,int n2)//output massive | |
{ | |
for (int n=0;n<n1;n++) | |
{ | |
for (int k=0;k<n2;k++) | |
cout<<setw(5)<<a[n][k]; | |
cout<<endl; | |
} | |
} | |
void out(int **a,int n, int k, int&num,int&qua)//output recent element | |
{ | |
num++;//number of outputed elements | |
cout<<setw(3)<<a[n][k]; | |
} | |
void zmeyka(int **a,int n1, int n2,int qua)//output zmeykoy | |
{ | |
cout<<endl; | |
int up=0,down=n1,right=n2,left=0,num=0;//mezhi vyvoda | |
while(!(num>=qua))//output zmeykoy | |
{ | |
for (int i=left;i<right;i++) | |
out(a,left,i,num,qua); | |
if (num>=qua) break; | |
for (int i=up+1;i<down;i++) | |
out(a,i,right-1,num,qua); | |
if (num>=qua) break; | |
for (int i=right-2;i>=left;i--) | |
out(a,down-1,i,num,qua); | |
if (num>=qua) break; | |
for (int i=down-2;i>=up+1;i--) | |
out(a,i,left,num,qua); | |
up++;//zvuzyty mezhi | |
down--; | |
left++; | |
right--; | |
} | |
cout<<endl; | |
} | |
void main() | |
{ | |
cout<<"executer is Vadym Goloveychuk, is22\ninput rows and coluns\n\n"; | |
srand(time(0)); | |
int n1,n2;//number of rows and columns | |
cout<<"enter number of rows and columns"<<endl; | |
cin>>n1>>n2; | |
int **a=new int* [n1];//dvovymerny dynamic massive | |
for(int k=0; k<n1;k++) a[k]=new int[n2];//dvovymerny dynamic massive | |
int key;//switcher | |
do | |
{ | |
cout<<"1. enter\n2. random\n"; | |
key=getch(); | |
switch(key)//switching | |
{ | |
case '1': input(a,n1,n2);flag=1;break;//manually inputting | |
case '2': random(a,n1,n2);flag=1;break;//random | |
default: cout<<"you entered other number"<<endl; | |
} | |
}while (!flag); | |
int qua=n1*n2;//number of elements,counter | |
outmassive(a,n1,n2);//output massive | |
zmeyka(a,n1,n2,qua);//output zmeykoy | |
system("pause"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string.h> | |
#include <conio.h> | |
using namespace std; | |
int n=100; | |
void del(char *b,char **mas,int&num,char *b_new)//deleting lexems | |
{ | |
char *b_copy=new char[n];//copy of source string | |
char *item=new char[n];//lexem of source string | |
bool flag=0;//flag of existing | |
char space[]=" ";//space symbol | |
strcpy(b_copy,b);//b to b_copy | |
item=strtok(b_copy," ");//first lexem | |
while (item)//all lexems | |
{ | |
for (int i=0;i<num;i++) | |
if (strcmpi(mas[i],item)==0)//comparing lexems with words | |
flag=1;//exist | |
if (!flag) | |
{ | |
strcat(b_new,item);//add to b_new curent item | |
strcat(b_new,space);//ad to b_new space symbol | |
} | |
flag=0; | |
item=strtok(NULL," ");//next lexems | |
} | |
} | |
void lexemy(char *a,char **mas,int&num) | |
{ | |
char *a_copy=new char[n];//copy of words string | |
char *item=new char[n];//current word | |
strcpy(a_copy,a);//copy word string to a_copy | |
item=strtok(a_copy," ");//first lexem | |
while (item)//all lexems | |
{ | |
mas[num]=item;//save lexems | |
num++;//next element/number of elements | |
item=strtok(NULL," ");//next lexems | |
} | |
} | |
void main() | |
{ | |
char *a=new char[n];//words string | |
char *b=new char[n];//source string | |
char *b_new=new char[n];//processed source string | |
char **mas=new char* [n];//massive of lexems | |
*b_new='\0';//initialize processed source string | |
int num=0;//number of elements | |
cout<<"Exexuter is Goloveychuk Vadym, is-22\nenter source string:"<<endl; | |
gets(b);//input source string | |
cout<<"enter string of words to delete:"<<endl; | |
gets(a);//input words string | |
lexemy(a,mas,num);//split string to lexems | |
del(b,mas,num,b_new);//delete lexems | |
cout<<"after deletting:"<<endl; | |
puts(b_new);//output processed string | |
system("pause"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment