fork download
  1. #include <iostream>
  2. #include <cstring>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. const int MAX_LINES = 20;
  7. const int MAX_LENGTH = 1000;
  8.  
  9. bool isValidCharacter(char c) {
  10. return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c == '*');
  11. }
  12.  
  13. void formatText(char text[][MAX_LENGTH + 1], int lineCount, int maxLength) {
  14. for (int i = 0; i < lineCount; ++i) {
  15. int lengthCurrentLine = strlen(text[i]);
  16. if (lengthCurrentLine == 0 || text[i][lengthCurrentLine - 1] == '*') {
  17. continue;
  18. }
  19. int numAsterisks = maxLength - lengthCurrentLine;
  20. char formattedLine[MAX_LENGTH + 1];
  21. for (int j = 0; j < numAsterisks; ++j) {
  22. formattedLine[j] = '*';
  23. }
  24. strcpy(formattedLine + numAsterisks, text[i]);
  25. formattedLine[maxLength] = '\0';
  26.  
  27. cout << formattedLine << "\n";
  28. }
  29. }
  30.  
  31. int main() {
  32. ifstream fin("input.txt");
  33. char text[MAX_LINES][MAX_LENGTH + 1];
  34. int lineCount = 0;
  35. int maxLength = 0;
  36. while (cin.getline(text[lineCount], MAX_LENGTH + 1)) {
  37. int length = strlen(text[lineCount]);
  38. if (length > maxLength) {
  39. maxLength = length;
  40. }
  41. ++lineCount;
  42. }
  43. formatText(text, lineCount, maxLength);
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0s 5280KB
stdin
am*mers*la*mare
am*mers*la*mare
stdout
am*mers*la*mare
am*mers*la*mare