Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<math.h>
- #include<string.h>
- using namespace std;
- struct stud
- {
- char* name;
- int bal;
- };
- struct payment
- {
- char* name; // ÔÈÎ ÷åëîâåêà â âèäå ñòðîêè
- char* date; // äàòà â âèäå ñòðîêè ôîðìàòà dd.mm.yy
- int sum; // ñóììà ïëàòåæà
- };
- char*task7(char* input,int N)
- {
- char*s=0;
- s=new char[N];
- for(int i=0;i<N;i++) s[i]=input[i];
- cout<<s;
- return s;
- }
- int find1(char*input)
- {
- int num=0;
- int len=strlen(input)+1;
- for (int i=0;i<len;i++)
- if (input[i]=='1') num++;
- return num;
- }
- int find2(char*input)
- {
- int num=0;
- int len=strlen(input)+1;
- for (int i=0;i<len;i++)
- if (input[i]=='2') num++;
- return num;
- }
- int find3(char*input)
- {
- int num=0;
- int len=strlen(input)+1;
- for (int i=0;i<len;i++)
- if (input[i]=='3') num++;
- return num;
- }
- char*task8(char* input)
- {
- int length=0;
- length=strlen(input)+find1(input)*3+find2(input)*2+find3(input)*2;
- char*result=new char[length+1];
- int j=0;
- int len=strlen(input)+1;
- for (int i=0;i<len;i++)
- { switch(input[i])
- {
- case '1':
- result[j]='o'; j++;
- result[j]='d'; j++;
- result[j]='i';j++;
- result[j]='n';j++;
- break;
- case '2':
- result[j]='d'; j++;
- result[j]='v'; j++;
- result[j]='a';j++;
- break;
- case '3':
- result[j]='t'; j++;
- result[j]='r'; j++;
- result[j]='i';j++;
- break;
- default:
- result[j]=input[i];
- j++;
- }
- }
- result[j++]=0;
- cout<<result;
- return result;
- }
- char*task9(char *input)
- {
- int i;
- int M=strlen(input);
- for (i=0;input[i];i++)
- if (input[i]!=' ') break;//íàøëè 1 ñèìâîë íå ïðîáåë
- int j;
- for (j=i;input[j];j++)
- if (input[j]==' ') break;//èíäåêñ 1 ïðîáåëà ïîñëå 1 ñëîâà
- int k;
- for(k=M-1;input[k];k--)
- if (input[k]!=' ') break;//ïîñëåäíèé ñèìâîë ïîñëåäíåãî ñëîâà
- int e;
- for (e=k-1;input[e];e--)
- if (input[e]==' ') break;// ïðîáåë ïåðåä ïåðâûì ñèìâîëîì ïîñëåäíåãî ñëîâà
- char * res=new char[M+1];
- int t;
- int length_input=0;
- int flag1=i-1;// äî ñîþäà ïèøåì ïðîáåëû â íà÷àëå
- int flag2=i+k-e;// äî ñþäà ïèøåì ïîñëåäíåå ñëîâî
- int flag3=i+k-j+1; // äî ñþäà ïèøåì âñþ ñòðîêó ïîäðÿä
- int flag4=i+k-j+1+j-i;//äî ñþäà ïèùåì 2 ñëîâî
- //cout<<"i="<<i;
- if (i!=0)
- {
- for (t=0;t<=flag1;t++) //çàïèñàëè ïðîáåëû â íà÷àëî ñòðîêè
- {
- res[t]=' ';
- length_input++;
- }
- }
- e++;
- for (t=length_input;t<=flag2;t++) //çàïèñàëè ïîñëåäíåå ñëîâî
- {
- res[t]=input[e];
- e++;
- length_input++;
- }
- //res[length_input]='0';
- length_input--;
- for(t=length_input;t<flag3;t++)//ïèøåì îñòàëüíóþ ñòðîêó
- {
- res[t]=input[j];
- j++;
- length_input++;
- }
- //cout<<length_input<<" "<<flag4<<" "<<i;
- for (t=length_input;t<=flag4;t++)//ïèøåì ïåðâîå ñëîâî
- {
- res[t]=input[i];
- //cout<<res[t];
- i++;
- length_input++;
- }
- if (k!=M)
- {
- for (t=length_input;t<=M;t++) //çàïèñàëè ïðîáåëû â êîíåö ñòðîêè
- {
- res[t]=' ';
- length_input++;
- }
- }
- res[M]=0;
- for (i=0;i<M;i++)cout<<res[i];
- return res;
- }
- char*task10(char*input)
- {
- int length=strlen(input);
- char*mas_simv=new char[length];
- char symbol;
- bool flag;
- int j=0;
- for (int i=0;i<length;i++)
- {
- symbol=input[i];
- flag=false;
- for (int k=0; k<length;k++)
- if (mas_simv[k]==symbol) flag=true;
- if (flag==false)
- {
- int count=0;
- for (int t=0;t<length;t++)
- if (input[t]==symbol) count++;
- mas_simv[j]=symbol;
- j++;
- cout<<symbol<<"="<<count<<endl;
- }
- }
- delete mas_simv;
- return 0;
- }
- char*task11(char*input)
- {
- char *result=0;
- int k=strlen(input);
- result=new char [(k+1)/2];
- int j=0;
- for(int i=0;i<k;i+=2,j++)
- {
- result[j]=input[i];
- }
- result[j]=0;
- cout<<result;
- delete result;
- return 0;
- }
- char**task12(char**mas,int B)
- {
- char**result;
- result=new char*[B];
- int i;
- for (i=0;i<=B;i++)
- {
- int p=0;
- int j=0;
- int k=strlen(mas[i]);
- for (j=0;j<k;j++)
- if (mas[i][j]==' ') break;// íàøëè ïðîáåë ïîñëå ôàìèëèè íó è ïåðåä èìåíåì êîòîðûé
- int flag=j;
- result[i]=new char[k+1];// ñùçäàëè â êîíå÷íîì ìàññèâå ñòðîêó äëèíîé êàê ýòà
- result[i][p]=mas[i][j+1];//çàñóíóëè òóäà 1 áóêâó èìåíè
- j++;
- p++;
- result[i][p]='.';
- p++;
- int q;
- for ( q=j;q<k;q++)
- if (mas[i][q]==' ') break;// èùåì ïðîáåë ïåðåä îò÷åñêòâîì
- result[i][p]=mas[i][q+1];//îïÿòü êîðî÷å áóêâó ïèøåì
- p++;
- result[i][p]='.';
- p++;
- /*for (j=0;j<k;j++)
- if (mas[i][j]==' ') break;*/// ïîòîì îïÿòü èùåì ãäå ôàìèëèÿ çàêàí÷èâàåòñÿ è îïÿòü çàïèñûâàåñ â ðåçóëüòàò òàì äàëüøå
- int m=0;
- for (m=p,j=0;j<flag;j++,m++)
- result[i][m]=mas[i][j];
- result[i][m]=0;
- }
- for (int i=1;i<=B;i++)//âûâîäèì
- {
- cout<<result[i];
- cout<<endl;
- }
- return result;
- }
- int* task13(int *p,int B)
- {
- int len=0;
- for(int i=0;i<B;i++)
- if ((p[i]%2)==0) len++;
- if (len==0)
- {
- int *q=0;
- cout<<"No chetnyx chisel";
- return q;
- }
- else
- {
- int *q=0;
- q=new int[len];
- int j=0;
- for(int i=0;i<B;i++)
- if ((p[i]%2)==0)
- {
- q[j]=p[i];
- j++;
- }
- for(j=0;j<len;j++)
- cout<<q[j]<<" ";
- return q;
- }
- }
- int task14(int*p,int B)
- {
- int length=B;
- int*mas_simv=new int[length];
- int symbol;
- bool flag;
- int j=0;
- for (int i=0;i<length;i++)
- {
- symbol=p[i];
- flag=false;
- for (int k=0; k<length;k++)
- if (mas_simv[k]==symbol) flag=true;
- if (flag==false)
- {
- mas_simv[j]=p[i];
- j++;
- }
- }
- for(int i=0;i<j;i++)
- cout<<mas_simv[i]<<" ";
- delete mas_simv;
- return 0;
- }
- int task15(char**mas,int B)
- {
- stud* people=new stud[B];
- for (int i=1;i<=B;i++)
- {
- people[i].name=new char[2];
- people[i].name=" ";
- people[i].bal=0;
- }
- int i=0;
- int tek_uk=1;
- for (i=1;i<=B;i++)
- {
- int length_data=strlen(mas[i]);
- int j=0;
- int j1=0;
- bool flag=true;
- bool flag_exist=false;
- for (j1=0;j1<length_data;j1++)//èùåì ïðîáåë
- {
- if (mas[i][j1]==' ') break;
- }
- for (j=j1+1;j<length_data;j++)//èùåì ïðîáåë
- {
- if (mas[i][j]==' ') break;
- }
- //òåïåðü j óêàçûâàåò íà ïðîáåë ïîñëå ÔÈÎ
- char*data=new char [j];//ïîìåñòèëè ôèî â data
- int p=0;
- for(p=0;p<j; p++)
- data[p]=mas[i][p];
- data[p]=0;
- //ñ÷èòûâàåì áûëëû ñî ñòðîêè
- int t=0;
- for ( t=j+1;t<length_data;t++)//èùåì ïðîáåë îïÿòü
- if(mas[i][t]==' ') break;
- char mark[4];
- for(int y=0;y<length_data;y++)
- {
- mark[y]=mas[i][t];
- t++;
- }
- int data_bal=atoi(mark);
- flag_exist=false;
- for(int k=1;k<=B;k++)//õîäèì ïî ñòðîêàì â ìàññèâå ñòðóêòóð è èùåì åñòü îí òàì óæå èëè íåò
- {
- if (strcmp(people[k].name,data)==0)
- {
- flag_exist=true;
- people[k].bal= people[k].bal+data_bal;
- }
- }
- if (flag_exist==false) //åñëè ýòîãî ÷åëîâåêà â ñïèñêå èòîãîâîì åùå íåò
- {
- people[tek_uk].name=new char[j];//âûäåëèëè ïàìÿòü ïîä èìÿ â ïîëå
- people[tek_uk].name=data;//çàïèñàëè èìÿ
- people[tek_uk].bal=data_bal;
- tek_uk++;
- }
- }
- int max=people[1].bal;
- for(int i=2;i<tek_uk;i++)
- if (max<people[i].bal) max=people[i].bal;
- for (int i=1;i<tek_uk;i++)
- if (max==people[i].bal) cout<<people[i].name<<" "<<people[i].bal<<endl;
- int l=0;
- cout<<"l=";
- cin>>l;
- //delete[]people;
- return 0;
- }
- payment* task16_1(int B)
- {
- int const M=8;
- const int N=500;
- payment *mas=new payment[B];
- for (int i=0;i<B;i++)
- {
- mas[i].name=new char[N];
- mas[i].date=new char[M];
- }
- for (int i=0;i<B;i++)
- {
- char input[100];
- cin.ignore(1);
- cin.getline(input,N);
- strcpy(mas[i].name,input);
- cin.getline(input,N);
- strcpy(mas[i].date,input);
- cin>>mas[i].sum;
- }
- for(int i=0;i<B;i++)
- cout<<mas[i].name<<" "<<mas[i].date<<" "<<mas[i].sum<<endl;
- /*for (int i=0;i<B;i++)
- {
- delete[]mas[i].name;
- delete[]mas[i].date;
- delete []mas;
- }*/
- return mas;
- }
- void task17(int B, char symbol)
- {
- int const M=8;
- const int N=500;
- payment *mas=new payment[B];
- for (int i=0;i<B;i++)
- {
- mas[i].name=new char[N];
- mas[i].date=new char[M];
- }
- for (int i=0;i<B;i++)
- {
- char input[100];
- cin.ignore(1);
- cin.getline(input,N);
- strcpy(mas[i].name,input);
- cin.getline(input,N);
- strcpy(mas[i].date,input);
- cin>>mas[i].sum;
- }
- for(int i=0;i<B;i++)
- if(mas[i].name[0]==symbol) cout<<mas[i].name<<" "<<mas[i].date<<" "<<mas[i].sum<<endl;
- }
- int main()
- {
- //const int N=500;
- //char input[N];
- /**cout<<"Put the line"<<endl;
- cin.getline(input,N);*/
- // task7(input,N);
- //task8(input);
- //task9(input);
- //task10(input);
- //task11(input);
- //task12(mas,B);
- //int B;
- //cout<<"Put the number of elements"<<endl;
- //cin>>B;
- //int *p=0;
- //p=new int[B];
- //for (int i=0;i<B;i++)cin>>p[i];
- ////task13(p,B);
- //task14(p,B);
- int B;
- cout<<"Put the number of elements"<<endl;
- cin>>B;
- /*char**mas=0;
- mas=new char*[B];
- for (int i=0;i<=B;i++)
- {
- mas[i]=new char[N];
- cin.getline(mas[i],N);
- }
- task15(mas,B);*/
- //task16_1(B);
- char symbol;
- cout<<"put symbol";
- cin>>symbol;
- task17(B,symbol);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement