Chciałbym prosić o ocenę programu, głównie pod kątem czystego kodu.
EDIT: Program ma za zadanie skrócenie napisu podanego przez użytkownika. Przykład AAABBCCCC zamienia na A3BBC4.
#include <iostream>
using namespace std;
void getSubtitles(char against[][201], int dimension);
void reduceSubtitles(char toChange[][201], int sizeOfSubtitles);
void makeSmaller(char toChange[]);
void cutRepeatsInSubtitle(char toChange[], char afterChange[], int i, int &j, int &sameLetters);
void moreThenThreeLettersInRow(char subtitle[], int &actualLetter, const int amountOfSameLettersInRow);
int changeDigitToAscii(int DigitToSwap);
void showSubtitles(char caption[][201], int amount);
int main()
{
int amount;
cin>>amount;
char inscription[amount][201];
getSubtitles(inscription,amount);
reduceSubtitles(inscription,amount);
showSubtitles(inscription,amount);
return 0;
}
void getSubtitles(char caption[][201], int amount)
{
for(int i=0;i<amount;i++)
cin>>caption[i];
}
void reduceSubtitles(char toChange[][201], int amount)
{
for(int i=0;i<amount;i++)
makeSmaller(toChange[i]);
}
void makeSmaller(char toChange[])
{
char afterChange[201];
int sameLetters=1, actualLetterAfterChange=0;
for(int i=0;toChange[i];i++)
cutRepeatsInSubtitle(toChange, afterChange, i, actualLetterAfterChange, sameLetters);
afterChange[actualLetterAfterChange]='\0';
int j;
for(j=0;afterChange[j];j++)
toChange[j]=afterChange[j];
while(j<201)
toChange[j++]='\0';
}
void cutRepeatsInSubtitle(char toChange[], char afterChange[], int i, int &j, int &sameLetters)
{
if(toChange[i]==toChange[i+1])
sameLetters++;
else if(sameLetters==1)
{
afterChange[j++]=toChange[i];
sameLetters=1;
}
else if (sameLetters==2)
{
afterChange[j++]=toChange[i-1];
afterChange[j++]=toChange[i];
sameLetters=1;
}
else
{
afterChange[j++]=toChange[i];
moreThenThreeLettersInRow(afterChange,sameLetters,j);
sameLetters=1;
}
}
void moreThenThreeLettersInRow(char subtitle[], int &actualLetter, const int amountOfSameLettersInRow)
{
if(amountOfSameLettersInRow>99)
subtitle[actualLetter++]=(char)changeDigitToAscii(amountOfSameLettersInRow/10/10);
if(amountOfSameLettersInRow>9)
subtitle[actualLetter++]=(char)changeDigitToAscii(amountOfSameLettersInRow/10);
subtitle[actualLetter++]=(char)changeDigitToAscii(amountOfSameLettersInRow%10);
}
int changeDigitToAscii(int DigitToSwap)
{
switch(DigitToSwap)
{
case 0: return 48; break;
case 1: return 49; break;
case 2: return 50; break;
case 3: return 51; break;
case 4: return 52; break;
case 5: return 53; break;
case 6: return 54; break;
case 7: return 55; break;
case 8: return 56; break;
case 9: return 57; break;
}
}
void showSubtitles(char caption[][201], int amount)
{
for(int i=0;i<amount;i++)
cout<<caption[i]<<endl;
}