Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. program check;
  2.  
  3. var
  4. input : string;
  5. a : array[1..12] of char;
  6. i : word;
  7. c : char;
  8. successful : boolean;
  9.  
  10. function is_valid_char(c : char) : boolean;
  11.  
  12. var
  13. i : word;
  14. successful2 : boolean;
  15. begin
  16. successful2 := false;
  17.  
  18. for i := 1 to 12 do
  19. begin
  20. if c = a[i] then //Does the character match the valid character at index i?
  21. begin
  22. successful2 := true; //Yes it does, set successful to true
  23.  
  24. break; //Stop loop, character is valid
  25. end;
  26. end;
  27.  
  28. exit(successful2); //If the character didn't match any of the values in the array then successful will still be false
  29. end;
  30.  
  31. begin
  32. write('Enter a string: ');
  33. readln(input);
  34.  
  35. a[1] := 'i';
  36. a[2] := 'I';
  37. a[3] := 'V';
  38. a[4] := 'v';
  39. a[5] := 'C';
  40. a[6] := 'c';
  41. a[7] := 'D';
  42. a[8] := 'd';
  43. a[9] := 'L';
  44. a[10] := 'l';
  45. a[11] := 'M';
  46. a[12] := 'n';
  47.  
  48. successful := true; //Set this to true so that if there are no invalid characters you can tell it succeeded
  49.  
  50. for i := 1 to length(input) do
  51. begin
  52. c := input[i]; //Get the array value of 'input' at index 'i'
  53.  
  54. if is_valid_char(c) <> true then //Is the character valid?
  55. begin
  56. successful := false; //We found an invalid character, set successful to false
  57.  
  58. break; //Break out of the loop, no point checking the rest
  59. end;
  60. end;
  61.  
  62.  
  63. if successful = true then //If there was an invalid character then successful would have been set to false
  64.  
  65. Begin
  66. rn:='';
  67. ReadLn(input);
  68. Temp:=input;
  69.  
  70. Repeat
  71. If (Temp = M)Then Begin
  72. D:=Temp Div 1000;
  73. For i:=1 To D Do Begin
  74. rn:=rn+'M';
  75. End;
  76.  
  77. Temp:= Temp Mod 1000;
  78. End
  79.  
  80. Else Temp:= Temp Mod 1000;
  81.  
  82. If (Temp Div 100 <> 0)Then Begin
  83. D:=Temp Div 100;
  84. Case (D) Of
  85. 1:rn:=rn+'C';
  86. 2:rn:=rn+'CC';
  87. 3:rn:=rn+'CCC';
  88. 4:rn:=rn+'CD';
  89. 5:rn:=rn+'D';
  90. 6:rn:=rn+'DC';
  91. 7:rn:=rn+'DCC';
  92. 8:rn:=rn+'DCCC';
  93. 9:rn:=rn+'CM';
  94. End;
  95. Temp:=Temp Mod 100;
  96. End;
  97.  
  98. If (Temp Div 10 <> 0) Then Begin
  99. D:=Temp Div 10;
  100. Case (D) Of
  101. 1:rn:=rn+'X';
  102. 2:rn:=rn+'XX';
  103. 3:rn:=rn+'XXX';
  104. 4:rn:=rn+'XL';
  105. 5:rn:=rn+'L';
  106. 6:rn:=rn+'LX';
  107. 7:rn:=rn+'LXX';
  108. 8:rn:=rn+'LXXX';
  109. 9:rn:=rn+'XC';
  110. End;
  111. Temp:=Temp Mod 10;
  112. End;
  113.  
  114. Case (Temp) Of
  115. 1:rn:=rn+'I';
  116. 2:rn:=rn+'II';
  117. 3:rn:=rn+'III';
  118. 4:rn:=rn+'IV';
  119. 5:rn:=rn+'V';
  120. 6:rn:=rn+'VI';
  121. 7:rn:=rn+'VII';
  122. 8:rn:=rn+'VIII';
  123. 9:rn:=rn+'IX';
  124. End;
  125.  
  126. Until Temp <= 10;
  127. Write(User,'=',rn);
  128. readln();
  129.  
  130. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement