Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,43 +0,0 @@
|
|||
<with Ada.Text_IO, Simple_Parse;
|
||||
|
||||
procedure Phrase_Reversal is
|
||||
|
||||
function Reverse_String (Item : String) return String is
|
||||
Result : String (Item'Range);
|
||||
begin
|
||||
for I in Item'range loop
|
||||
Result (Result'Last - I + Item'First) := Item (I);
|
||||
end loop;
|
||||
return Result;
|
||||
end Reverse_String;
|
||||
|
||||
function Reverse_Words(S: String) return String is
|
||||
Cursor: Positive := S'First;
|
||||
Word: String := Simple_Parse.Next_Word(S, Cursor);
|
||||
begin
|
||||
if Cursor > S'Last then -- Word holds the last word
|
||||
return Reverse_String(Word);
|
||||
else
|
||||
return Reverse_String(Word) & " " & Reverse_Words(S(Cursor .. S'Last));
|
||||
end if;
|
||||
end Reverse_Words;
|
||||
|
||||
function Reverse_Order(S: String) return String is
|
||||
Cursor: Positive := S'First;
|
||||
Word: String := Simple_Parse.Next_Word(S, Cursor);
|
||||
begin
|
||||
if Cursor > S'Last then -- Word holds the last word
|
||||
return Word;
|
||||
else
|
||||
return Reverse_Order(S(Cursor .. S'Last)) & " " & Word;
|
||||
end if;
|
||||
end Reverse_Order;
|
||||
|
||||
Phrase: String := "rosetta code phrase reversal";
|
||||
use Ada.Text_IO;
|
||||
begin
|
||||
Put_Line("0. The original phrase: """ & Phrase & """");
|
||||
Put_Line("1. Reverse the entire phrase: """ & Reverse_String(Phrase) & """");
|
||||
Put_Line("2. Reverse words, same order: """ & Reverse_Words(Phrase) & """");
|
||||
Put_Line("2. Reverse order, same words: """ & Reverse_Order(Phrase) & """");
|
||||
end Phrase_Reversal;
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
program-id. phra-rev.
|
||||
data division.
|
||||
working-storage section.
|
||||
1 phrase pic x(28) value "rosetta code phrase reversal".
|
||||
1 wk-str pic x(16).
|
||||
1 binary.
|
||||
2 phrase-len pic 9(4).
|
||||
2 pos pic 9(4).
|
||||
2 cnt pic 9(4).
|
||||
procedure division.
|
||||
compute phrase-len = function length (phrase)
|
||||
display phrase
|
||||
display function reverse (phrase)
|
||||
perform display-words
|
||||
move function reverse (phrase) to phrase
|
||||
perform display-words
|
||||
stop run
|
||||
.
|
||||
|
||||
display-words.
|
||||
move 1 to pos
|
||||
perform until pos > phrase-len
|
||||
unstring phrase delimited space
|
||||
into wk-str count in cnt
|
||||
with pointer pos
|
||||
end-unstring
|
||||
display function reverse (wk-str (1:cnt))
|
||||
with no advancing
|
||||
if pos < phrase-len
|
||||
display space with no advancing
|
||||
end-if
|
||||
end-perform
|
||||
display space
|
||||
.
|
||||
end program phra-rev.
|
||||
|
|
@ -7,12 +7,12 @@ public program()
|
|||
var reverse := (s => s.toArray().sequenceReverse().summarize(new StringWriter()));
|
||||
|
||||
var phrase := "rosetta code phrase reversal";
|
||||
console.printLine(phrase);
|
||||
Console.printLine(phrase);
|
||||
|
||||
//Reverse the string
|
||||
console.printLine(reverse(phrase));
|
||||
Console.printLine(reverse(phrase));
|
||||
//Reverse each individual word in the string, maintaining original string order.
|
||||
console.printLine(phrase.splitBy(" ").selectBy::(s => reverse(s).add(" ")).summarize(new StringWriter()));
|
||||
Console.printLine(phrase.splitBy(" ").selectBy::(s => reverse(s).add(" ")).summarize(new StringWriter()));
|
||||
//Reverse the order of each word of the phrase, maintaining the order of characters in each word.
|
||||
console.printLine(reverse(phrase.splitBy(" ").selectBy::(s => s + " ")))
|
||||
Console.printLine(reverse(phrase.splitBy(" ").selectBy::(s => s + " ")))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
(defun reverse-sep (words sep)
|
||||
(mapconcat 'identity (reverse (split-string words sep)) sep))
|
||||
|
||||
(defun reverse-chars (line)
|
||||
(reverse-sep line ""))
|
||||
|
||||
(defun reverse-words (line)
|
||||
(reverse-sep line " "))
|
||||
|
||||
(defvar line "rosetta code phrase reversal")
|
||||
|
||||
(with-output-to-temp-buffer "*reversals*"
|
||||
(princ (reverse-chars line))
|
||||
(terpri)
|
||||
(princ (mapconcat 'identity (mapcar #'reverse-chars
|
||||
(split-string line)) " "))
|
||||
(terpri)
|
||||
(princ (reverse-words line))
|
||||
(terpri))
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
import java.util.Arrays;
|
||||
|
||||
public class PhraseRev{
|
||||
private static String reverse(String x){
|
||||
return new StringBuilder(x).reverse().toString();
|
||||
}
|
||||
|
||||
private static <T> T[] reverse(T[] x){
|
||||
T[] rev = Arrays.copyOf(x, x.length);
|
||||
for(int i = x.length - 1; i >= 0; i--){
|
||||
rev[x.length - 1 - i] = x[i];
|
||||
}
|
||||
return rev;
|
||||
}
|
||||
|
||||
private static String join(String[] arr, String joinStr){
|
||||
StringBuilder joined = new StringBuilder();
|
||||
for(int i = 0; i < arr.length; i++){
|
||||
joined.append(arr[i]);
|
||||
if(i < arr.length - 1) joined.append(joinStr);
|
||||
}
|
||||
return joined.toString();
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
String str = "rosetta code phrase reversal";
|
||||
|
||||
System.out.println("Straight-up reversed: " + reverse(str));
|
||||
String[] words = str.split(" ");
|
||||
for(int i = 0; i < words.length; i++){
|
||||
words[i] = reverse(words[i]);
|
||||
}
|
||||
System.out.println("Reversed words: " + join(words, " "));
|
||||
System.out.println("Reversed word order: " + join(reverse(str.split(" ")), " "));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
function reverse($a, $sep = "") {
|
||||
if($a.Length -gt 0) {
|
||||
$a = $a[($a.Length -1)..0] -join $sep
|
||||
}
|
||||
$a
|
||||
}
|
||||
$line = "rosetta code phrase reversal"
|
||||
$task1 = reverse $line
|
||||
$task2 = ($line -split " " | foreach{ reverse $_ }) -join " "
|
||||
$task3 = reverse ($line -split " ") " "
|
||||
$task1
|
||||
$task2
|
||||
$task3
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
Phrase = "rosetta code phrase reversal"
|
||||
|
||||
WScript.StdOut.Write "Original String : " & Phrase
|
||||
WScript.StdOut.WriteLine
|
||||
WScript.StdOut.Write "Reverse String : " & RevString(Phrase)
|
||||
WScript.StdOut.WriteLine
|
||||
WScript.StdOut.Write "Reverse String Each Word : " & RevStringEachWord(Phrase)
|
||||
WScript.StdOut.WriteLine
|
||||
WScript.StdOut.Write "Reverse Phrase : " & RevPhrase(Phrase)
|
||||
WScript.StdOut.WriteLine
|
||||
|
||||
Function RevString(s)
|
||||
x = Len(s)
|
||||
For i = 1 To Len(s)
|
||||
RevString = RevString & Mid(s,x,1)
|
||||
x = x - 1
|
||||
Next
|
||||
End Function
|
||||
|
||||
Function RevStringEachWord(s)
|
||||
arr = Split(s," ")
|
||||
For i = 0 To UBound(arr)
|
||||
RevStringEachWord = RevStringEachWord & RevString(arr(i))
|
||||
If i < UBound(arr) Then
|
||||
RevStringEachWord = RevStringEachWord & " "
|
||||
End If
|
||||
Next
|
||||
End Function
|
||||
|
||||
Function RevPhrase(s)
|
||||
arr = Split(s," ")
|
||||
For i = UBound(arr) To LBound(arr) Step -1
|
||||
RevPhrase = RevPhrase & arr(i)
|
||||
If i > LBound(arr) Then
|
||||
RevPhrase = RevPhrase & " "
|
||||
End If
|
||||
Next
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue