fork download
  1. using System;
  2.  
  3. namespace BasicFormat {
  4. class Program {
  5. static int lineCount;
  6. static string indent;
  7.  
  8. static void Main() {
  9. lineCount = int.Parse(Console.ReadLine());
  10. string[] inputCode = new string[lineCount];
  11. indent = Console.ReadLine();
  12. int i = 0;
  13. string line;
  14. while (i < lineCount) {
  15. line = Console.ReadLine();
  16. inputCode[i] = line;
  17. i++;
  18. }
  19. Console.Write(FormatCode(inputCode));
  20. }
  21.  
  22. static string FormatCode(string[] lines) {
  23. string result = "";
  24. string emptyLine, startsWith;
  25. int indentLevel = 0;
  26. for (int i = 0; i < lineCount; i++) {
  27. emptyLine = string.Join("", lines[i].Split('»', '·'));
  28. startsWith = emptyLine.Split()[0];
  29. if (startsWith == "ENDIF" || startsWith == "NEXT") {
  30. indentLevel -= 1;
  31. }
  32. for (int j = 0; j < indentLevel; j++) {
  33. result += indent;
  34. }
  35. result += emptyLine + "\n";
  36. if (startsWith == "IF" || startsWith == "FOR") {
  37. indentLevel += 1;
  38. }
  39. }
  40. return result;
  41. }
  42. }
  43. }
Success #stdin #stdout 0.04s 24016KB
stdin
12
····
VAR I
·FOR I=1 TO 31
»»»»IF !(I MOD 3) THEN
··PRINT "FIZZ"
··»»ENDIF
»»»»····IF !(I MOD 5) THEN
»»»»··PRINT "BUZZ"
··»»»»»»ENDIF
»»»»IF (I MOD 3) && (I MOD 5) THEN
······PRINT "FIZZBUZZ"
··»»ENDIF
»»»»·NEXT
stdout
VAR I
FOR I=1 TO 31
····IF !(I MOD 3) THEN
········PRINT "FIZZ"
····ENDIF
····IF !(I MOD 5) THEN
········PRINT "BUZZ"
····ENDIF
····IF (I MOD 3) && (I MOD 5) THEN
········PRINT "FIZZBUZZ"
····ENDIF
NEXT