Advertisement
Guest User

2018-4

a guest
Jan 18th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5.  
  6. void wyswietl(char* napis)
  7. {
  8. int licz_slowa=1;
  9. for(int i=0; i<strlen(napis); i++)
  10. {
  11. if (napis[i] == ' ') licz_slowa++;
  12. }
  13. //cout << "liczba slow to " << licz_slowa << endl;
  14. char** slowa = new char*[licz_slowa];
  15. for(int i=0; i<licz_slowa; i++)
  16. slowa[i]=new char[255];
  17.  
  18. int indeks1 = 0;
  19. int indeks2 = 0;
  20. for(int i=0; i<strlen(napis); i++)
  21. {
  22. if(napis[i]!=' ')
  23. {
  24. slowa[indeks1][indeks2] = napis[i];
  25. indeks2++;
  26. }
  27. else
  28. {
  29. indeks1++;
  30. indeks2=0;
  31. }
  32. }
  33.  
  34. int indeks_docelowy = 0;
  35. int najw = 0;
  36. int indeksy[100];
  37. int liczmax = 1;
  38. for(int i=0; i<licz_slowa; i++)
  39. {
  40. int temp = 0;
  41. int dlugosc = strlen(slowa[i]);
  42. for(int j=0; j<dlugosc; j++)
  43. {
  44. for(int k=0; k<dlugosc; k++)
  45. {
  46. if(slowa[i][j]==slowa[i][k] || slowa[i][j]==slowa[i][k]+32 || slowa[i][j]==slowa[i][k]-32) temp++;
  47. }
  48. }
  49. if(temp>najw)
  50. {
  51. najw=temp;
  52. indeks_docelowy=i;
  53. indeksy[0] = i;
  54. liczmax = 1;
  55. }
  56. if(temp==najw)
  57. {
  58. liczmax++;
  59. indeksy[liczmax-1]=i;
  60. }
  61. }
  62.  
  63. for(int i=1; i<liczmax; i++)
  64. {
  65. cout << slowa[indeksy[i]] << endl;
  66. }
  67. }
  68.  
  69.  
  70. int main()
  71. {
  72. char napis[]={"hejka nooon ooonn nnooo"};
  73. wyswietl(napis);
  74. return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement