Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- using namespace std;
- char* StringCopy(char* s)
- {
- char* Str = 0;
- int len = 0;
- for (int i = 0; s[i]; i++){
- len++;
- }
- len++;
- Str = new char [len];
- for (int i = 0; i<len; i++)
- Str[i] = s[i];
- return Str;
- };
- char* StringRename(char* s)
- {
- char* Str = 0;
- int len =0, counter1 = 0, counter2 = 0, counter3 = 0;
- for (int i=0;s[i];i++)
- {
- if (s[i]=='1')
- counter1++;
- if (s[i]=='2')
- counter2++;
- if (s[i]=='3')
- counter3++;
- }
- int lenght=strlen(s)+counter1*2+counter2*2+counter3*4;
- int j = 0;
- int lenString = strlen(s);
- Str = new char [lenght+1];
- for (int i = 0; i<lenString; i++)
- {
- switch (s[i])
- {
- case '1':
- Str[j] = 'O';
- Str[j+1] = 'n';
- Str[j+2] = 'e';
- j+=2;
- break;
- case '2':
- Str[j] = 'T';
- Str[j+1] = 'w';
- Str[j+2] = 'o';
- j+=2;
- break;
- case '3':
- Str[j] = 'T';
- Str[j+1] = 'h';
- Str[j+2] = 'r';
- Str[j+3] = 'e';
- Str[j+4] = 'e';
- j+=4;
- break;
- default:
- Str[j] = s[i];
- break;
- }
- j++;
- }
- Str[lenght]=0;
- return Str;
- }
- bool SearchWord(char* s,int& bLet,int& FirstIndex,int& LastIndex)
- {
- for (;s[bLet]; bLet++)
- {
- if (!(s[bLet]==' '))
- {
- FirstIndex=bLet;
- break;
- }
- }
- if (!s[bLet]){ return false;}
- for (;s[bLet];bLet++)
- {
- if (s[bLet]==' ')
- break;
- }
- LastIndex=bLet;
- return true;
- }
- char* WordsSwap(char* s)
- {
- char* Str = 0;
- int length=strlen(s);
- int beginLetter = 0;
- int fwb = 0;
- int fwe = 0;
- if(!SearchWord(s,beginLetter, fwb, fwe)) {
- cout << "нет первого слова";
- return s;
- }
- int lwb = 0;
- int lwe = 0;
- while (SearchWord(s,beginLetter,lwb,lwe)){}
- if (!lwb) {return s;}
- char* newStr = new char [length];
- int count=0;
- int lwbcount=lwb;
- int fwecount=fwe;
- int lwecount=lwe;
- int fwbcount=fwb;
- for (int i=0;i<fwb;i++){
- newStr[count]=s[i];
- count++;
- }
- for (lwb;lwbcount<lwe;lwbcount++){
- newStr[count]=s[lwbcount];
- count++;
- }
- for (fwe;fwecount<lwb;fwecount++){
- newStr[count]=s[fwecount];
- count++;
- }
- for (fwb;fwbcount<fwe;fwbcount++){
- newStr[count]=s[fwbcount];
- count++;
- }
- for (lwe;lwecount<length;lwecount++){
- newStr[count]=s[lwecount];
- count++;
- }
- newStr[count]=0;
- return newStr;
- }
- void NumberOfLatinSymbolsIncluded(char* s)
- {
- int i = 0;
- int A [26];
- for(int i = 0; i<26; i++)
- {
- A[i]=0;
- }
- while (s[i])
- { if ((s[i]>='A') && (s[i]<='Z'))
- A[s[i]-'A']++;
- else if ((s[i]>='a') && (s[i]<='z')
- {A[s[i]-'a']++;}
- i++;
- }
- for(int j = 0; j<26; j++)
- {
- cout << A[j] << " ";
- }
- }
- char* DeleteEachSecondSymbolInString(char *s)
- {
- char* Str = 0;
- int lenght = 0;
- lenght = (strlen(s)+(strlen(s)%2==0 ? 0 : 1))/2;
- Str = new char [lenght+1];
- int j = 0;
- for (int i = 0; i<strlen(s); i+=2)
- {
- Str[j] = s[i];
- j++;
- }
- Str[lenght] = 0;
- return Str;
- }
- char** ArrayChange(char** mas, int M)
- {
- char** table = 0;
- table = new char* [M];
- for (int i = 0; i<M; i++)
- {
- int j = 0;
- int len = strlen(mas[i]);
- for (j; mas[i][j]; j++)
- if (mas[i][j]==' ')
- break;
- table[i] = new char [j+7];
- table[i][0] = mas[i][j+1];
- table[i][1] = '.';
- table[i][2] = ' ';
- int k ;
- for (k = j+1; mas[i][j]; k++)
- if (mas[i][k]==' ')
- break;
- table[i][3] = mas[i][k+1];
- table[i][4] = '.';
- table[i][5] = ' ';
- for (int q = 0; q<j; q++)
- table[i][q+6] = mas[i][q];
- //table[i][j+6] = ';';
- table[i][j+6] = 0;
- }
- return table;
- }
- int* ArrayContainAllEvenNumbers(int* mas, int size, int &cnr)
- {
- cnr = 0;
- int *res = 0;
- for (int i = 0; i<size; i++)
- if (mas[i]%2==0)
- cnr++;
- res = new int [cnr];
- int j = 0;
- for (int i = 0; i<size; i++)
- {
- if (mas[i]%2==0)
- {
- res[j] = mas[i];
- j++;
- }
- }
- return res;
- }
- // -1163005939
- int AllSymbolsTakenOneTime(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<j;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 main(){
- char* MyString = 0;
- char* NewStr = 0;
- const int N= 100;
- char string[N];
- // cout << "Enter the string:" << endl;
- // cin.getline(string, N);
- /*MyString = StringCopy(string);
- cout << MyString << endl;
- NewStr = StringRename(MyString);
- cout << NewStr << endl;
- */
- //NewStr = WordsSwap(string);
- // cout << NewStr << endl;
- // NumberOfLatinSymbolsIncluded(string);
- /*
- cout << DeleteEachSecondSymbolInString(string) << endl;
- */
- /*
- int M = 0;
- char ** mas = 0;
- cout << "How many students will be?" << endl;
- cin >> M;
- cin.ignore(256,'\n');
- cout << "Enter F.I.O of these students:" << endl;
- mas = new char* [M];
- for (int i = 0; i<M; i++)
- {
- cin.getline(string, N);
- mas[i] = StringCopy(string);
- }
- mas = ArrayChange(mas, M);
- for (int i = 0; i<M; i++)
- {
- cout << mas[i] << endl;
- }
- */
- /*
- int size = 0, cnr=0;
- cout << "How many elements will be?" << endl;
- cin >> size;
- int* massiv = 0;
- massiv = new int [size];
- cout << "Inpunt string of " << size << " numbers." << endl;
- for (int i = 0; i<size; i++)
- cin >> massiv[i];
- int* NewMas = 0;
- NewMas = ArrayContainAllEvenNumbers(massiv, size, cnr);
- if (cnr==0) cout << "There are no even numbers." << endl;
- else
- {
- cout << "Array of all even numbers: ";
- for (int i = 0; i<cnr; i++)
- cout << NewMas[i] << " ";
- cout << endl;
- }
- cnr=0;
- */
- 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];
- AllSymbolsTakenOneTime(p,B);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement