SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int isCharToDetermine(char* symbols, int size, char charToLookUp){
  5.     for (int i = 0; i < size; i++) {
  6.         if(symbols[i]==charToLookUp){
  7.             return i;
  8.         }
  9.     }
  10.     return -1;
  11. }
  12.  
  13. int calcOccurences(char* symbols, int size, char* sentences, int* occurences) {
  14.     char *p=sentences;
  15.     while(*p!='\0'){
  16.         int pos = isCharToDetermine(symbols, size, *p);
  17.         if(pos!=-1){
  18.             occurences[pos]++;
  19.         }
  20.         p++;
  21.     }
  22.     return 0;
  23. }
  24.  
  25.  
  26. int transformString(char *sentence, char mostChar, char leastChar){
  27.     char *p=sentence;
  28.     unsigned pos = 0;
  29.     while(*p!='\0') {
  30.         if(*p==mostChar){
  31.             sentence[pos] = leastChar;
  32.         }
  33.         else if(*p==leastChar){
  34.             sentence[pos] = mostChar;
  35.         }
  36.         pos++;
  37.         p++;
  38.     }
  39.  
  40.     return 0;
  41. }
  42.  
  43. int main()
  44. {
  45.     int numSymbolsToLook;
  46.     cin >> numSymbolsToLook;
  47.     char* Symbols = new char[numSymbolsToLook];
  48.  
  49.     int* occurances = new int[numSymbolsToLook];
  50.     for (int i = 0; i < numSymbolsToLook; i++){
  51.         cin>>Symbols[i];
  52.         occurances[i]=0;
  53.     }
  54.  
  55.  
  56.     cin.ignore();
  57.  
  58.     char* sentence = new char [59];
  59.     cin.getline(sentence, 60);
  60.  
  61.     calcOccurences(Symbols, numSymbolsToLook, sentence, occurances);
  62.  
  63.  
  64.     int leastPos = 0;
  65.     for(unsigned i=1; i<numSymbolsToLook; i++){
  66.         if(occurances[i]<occurances[leastPos]){
  67.             leastPos = i;
  68.         }
  69.     }
  70.  
  71.     int mostPost = 0;
  72.     for(unsigned i=1; i<numSymbolsToLook; i++){
  73.         if(occurances[i]>occurances[mostPost]){
  74.             mostPost = i;
  75.         }
  76.     }
  77.  
  78.     transformString(sentence, Symbols[mostPost], Symbols[leastPos]);
  79.  
  80.     cout<<Symbols[mostPost]<<" е най-често срещаният символ, който принадлежи на множеството\n";
  81.     cout<<Symbols[leastPos]<<" е най-рядко срещаният символ, който принадлежи на множеството\n";
  82.  
  83.     cout<<sentence<<endl;
  84.     return 0;
  85. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top