Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Plain Text by Pastew ( 13 years ago )
//Napisz funkjcę, która jako argument otrzymuje c-string. Funkcja ma zwrócić najczęściej i najrzadziej występującą literę.
#include<iostream>
#include<string>
using namespace std;

char najczesciej(string tekst)
{
 const unsigned alfabet=25;
 unsigned tab[alfabet];
 for(int i=0 ; i<alfabet ; i++)
  tab[i]=0;


 for(int i=0 ; i<tekst.length() ; i++)
  tab[tekst[i]-97]+=1;

 unsigned max=0,indeks;
 for(int i=0 ; i<alfabet ; i++)
  if(tab[i]>max) {max=tab[i];
  indeks=i;
 }
 return indeks+97;
};




int main(int argc, char* argv[])
{
 string tekst;
 cout << "Podaj tekst: ";
 cin >> tekst;

 cout << "\nW tekscie [ " << tekst << " ] najczesciej wystepuje litera: " << najczesciej(tekst);
 //cout << "W tekscie [ " << tekst << " ] najrzadziej wystepuje litera: " << najrzadziej(tekst);
 cout<<endl;
 system&#40;"pause"&#41;;
}

 

Revise this Paste

Your Name: Code Language: