编写一个函数/方法,该函数可以使用北约拼音字母输入字符串并拼写出该单词。标题箱可选


17

编写一个程序,该程序使用北约拼音字母输入字符串并拼写出该单词。

映射如下:

'A' -> 'Alfa'
'B' -> 'Bravo'
'C' -> 'Charlie'
'D' -> 'Delta'
'E' -> 'Echo'
'F' -> 'Foxtrot'
'G' -> 'Golf'
'H' -> 'Hotel'
'I' -> 'India'
'J' -> 'Juliett'
'K' -> 'Kilo'
'L' -> 'Lima'
'M' -> 'Mike'
'N' -> 'November'
'O' -> 'Oscar'
'P' -> 'Papa'
'Q' -> 'Quebec'
'R' -> 'Romeo'
'S' -> 'Sierra'
'T' -> 'Tango'
'U' -> 'Uniform'
'V' -> 'Victor'
'W' -> 'Whiskey'
'X' -> 'Xray'
'Y' -> 'Yankee'
'Z' -> 'Zulu'

例:

'Hello World' -> ['Hotel', 'Echo', 'Lima', 'Lima', 'Oscar', 'Whiskey', 'Oscar', 'Romeo', 'Lima', 'Delta']

输入可以是任何字符串,但始终仅由字母和空格组成。输出中的大小写无关,但是输入中可能包含大写字母,小写字母或两者都包含。在输出中应忽略空格。

您可以以任何合理的格式输出,但必须是一组定界的北约呼号。


4
欢迎来到PPCG!这个问题已经被问过了。但是无论如何,它可能还是会因其他一些原因而被关闭:1)除非有充分的理由,否则通常会以特定语言要求以特定方式(函数)回答。2)挑战必须是自成体系的:您应该解释北约拼音字母在问题正文中的确切含义。3)在当前形式下,它看起来像是一项家庭作业。如果是这样,您可能会在Stack Overflow上找到帮助,但前提是您要包括到目前为止所做的一切并说明问题所在。
Arnauld

4
如果上面提到的@Arnauld问题得到解决,因为它没有源代码限制或链接质询的输入验证,则我建议重新打开此代码。
毛茸茸的

1
我对其进行了编辑,使其可能可以重新打开,因为它对字符没有限制。我所有的更改都合适吗?特别是检查输入限制。
Rɪᴋᴇʀ

10
这是国际民航组织的字母;北约字母使用AlphaJuliet代替。
尼尔,

2
Whisky在示例中不等于Whiskey在映射中。
mazzy

Answers:


13

sfk78 59 57字节

+filt
+spell -nato
+xed _ph_f_ _et_ett_ _-__ "*: [keep]""

在线尝试!

只需使用正确的工具即可。

输出是由一个或多个空格分隔的语音。


6

IBM PC DOS 8088组件, 208 204 197 194 192字节

be80 00ad 8ac8 ac51 24df 8ad0 2c40 3c1b 7321 8af0 b024 b18b 9090 bf37 01f2 aefe
ce75 fab4 02cd 218b d7b4 09cd 21b2 20b4 02cd 2159 e2d0 c324 6c66 6124 7261 766f
2468 6172 6c69 6524 656c 7461 2463 686f 246f 7874 726f 7424 6f6c 6624 6f74 656c
246e 6469 6124 756c 6965 7474 2469 6c6f 2469 6d61 2469 6b65 246f 7665 6d62 6572
2473 6361 7224 6170 6124 7565 6265 6324 6f6d 656f 2469 6572 7261 2461 6e67 6f24
6e69 666f 726d 2469 6374 6f72 2468 6973 6b65 7924 7261 7924 616e 6b65 6524 756c
7524

下载DOS NATO.COM可执行文件:

离线尝试!(在DOSBox等中)

        TITLE NATO3
_TEXT   SEGMENT
        ASSUME CS:_TEXT,DS:_TEXT,ES:_TEXT,SS:_TEXT
        ORG     100H

START:
    MOV  SI, 80H            ; point SI to DOS PSP
    LODSW                   ; load arg length into AL, advance SI to 82H
    MOV  CL, AL             ; set up loop counter
SEARCH:
    LODSB                   ; load next char from DS:SI into AL, advance SI 
    PUSH CX                 ; save outer loop position
    AND  AL, 0DFH           ; uppercase the input letter
    MOV  DL, AL             ; save for output
    SUB  AL, 'A'-1          ; convert letter to one-based index (A=1, Z=26, etc)
    CMP  AL, 27             ; if greater than 26, not a valid char
    JNC  NOTFOUND           ; if not, move to next
    MOV  DH, AL             ; DH is loop counter
    MOV  AL, '$'            ; search for string delimiter
    MOV  CL, LNATO          ; repeat search through length of word data
    MOV  DI, OFFSET NATO    ; re-point SCASB to beginning of word data
SCANLOOP:
    REPNZ SCASB             ; search until delimiter in AL is found ES:DI, advance DI
    DEC  DH                 ; delimiter found, decrement counter
    JNZ  SCANLOOP           ; if counter reached 0, index has been found
    MOV  AH, 02H            ; display first char
    INT  21H
    MOV  DX, DI             ; put found string memory location to DX for display
    MOV  AH, 09H            ; display string function
    INT  21H
    MOV  DL, ' '            ; display a space between words
    MOV  AH, 02H
    INT  21H
NOTFOUND:
    POP  CX                 ; restore outer loop counter
    LOOP SEARCH             ; move to next char in input
    RET
NATO    DB  '$lfa$ravo$harlie$elta$cho$oxtrot$olf$otel$ndia$'
        DB  'uliett$ilo$ima$ike$ovember$scar$apa$uebec$omeo$'
        DB  'ierra$ango$niform$ictor$hiskey$ray$ankee$ulu$'
LNATO   EQU $-NATO

_TEXT ENDS
END START

测试输出:

A>NATO abc aaa
Alfa Bravo Charlie Alfa Alfa Alfa 
A>NATO abc DefG1HIJ
Alfa Bravo Charlie Delta Echo Foxtrot Golf Hotel India Juliett 
A>NATO Alfa Bravo!
Alfa Lima Foxtrot Alfa Bravo Romeo Alfa Victor Oscar 

更新以从单词列表数组中删除第一个字符(尽管由于附加的必需代码仅保存11个字节)。


您可以通过弄清楚如何关闭NOP填充或使用不执行此操作的其他版本来节省2个字节。我使用了ML.EXE,但它不执行填充操作。您可以通过删除$分隔符并通过大写第一个字母来分隔单词来节省另外18个字节左右(第一个单词是第二个字母,因为您已经省略了第一个字母)。(在进行解压缩所需的代码长度超过压缩的优势之前,可能会达到更高的压缩水平,但是简单的大写字母分隔符方案将是一个不错的开始。)
Deadcode,

1
使用MASM 5,我尝试了ALIGN和EVEN的所有变体,并移动了指令,无论它在REPNZ之前真正想要装什么。$分隔符是同时分隔数组和字符串分隔符的一种便宜方法,因此我可以使用INT 21H:09,而不必编写循环结构逐字符打印它。我喜欢您关于使用大写字母作为分隔符的想法,例如“ LfaRavoHarlie”,是吗?根据规范,大小写是无关紧要的,因此输出ALfa或CHarlie将是完全可以接受的。好主意!将需要对其进行编码,并查看最终的差异大小。
640KB

显然,MASM 9是最后一个具有/ AT​​选项的版本(对于.MODEL TINY),在我的代码测试中,它没有执行NOP填充。该ML.EXE /?输出显示Microsoft (R) Macro Assembler Version 9.00.30729.01。是的,“ LfaRavoHarlie”正是我的意思。:)我将执行“ OR AL,20H”以使其在输出中再次小写,但这取决于您。
Deadcode

顺便说一句,为什么在未组装的视图中不包括页眉和页脚?没有它,MASM 9不会为我编译它。我的意思是.MODEL TINY .CODE ORG 100H START:在开始和END START结束时。使用MASM 5编译时不需要吗?
Deadcode

我通常不包括MASM样板,因为它不是汇编代码的一部分(您可以通过多种方式获得相同的字节码,具体取决于您的MASM版本和所有版本)。我使用“旧”语法,因为我想在MASM 1.1上对其进行测试。:)我相信我已经发现了NOP问题,并且可能是MASM错误至少存在于1.1和5之间。如果将LNATO EQU放在代码或硬代码08BH上方,则不会插入两个NOP。但是,由于LNATO EQU在代码下方,因此pass1和pass2之间的操作有所不同,在那里留有空间。怪异的!
640KB

5

05AB1E102 96 95 字节

álSA”AlfaІvo¼¯¤œ®È¨›trotŠˆƒ‹Š™ÈŸtt Kilo´àma—……ÍЗŽêpa¼°«Äoµ†Çâgo¸šÉµ Whiskey Xrayµ‹nkeeâ¸lu”#‡

输出是带有标题区分大小写的北约单词的列表。

在线尝试。

说明:

á              # Only leave the letters of the (implicit) input
 l             # Convert it to lowercase
  S            # Split it to a list of characters
   A           # Push the alphabet
    ”...”      # Push all the NATO words in titlecase and space-delimited
         #     # Split the string by spaces
              # Transliterate; map all letters in the lowercase input with this
               # list at the same indices (and output the resulting list implicitly)

见我这个05AB1E尖端(部分如何使用字典?理解为什么”AlfaІvo¼¯¤œ®È¨›trotŠˆƒ‹Š™ÈŸtt Kilo´àma—……ÍЗŽêpa¼°«Äoµ†Çâgo¸šÉµ Whiskey Xrayµ‹nkeeâ¸lu”"Alfa Bravo Charlie Delta Echo Foxtrot Golf Hotel India Juliett Kilo Lima Mike November Oscar Papa Quebec Romeo Sierra Tango Uniform Victor Whiskey Xray Yankee Zulu"。这种压缩字典字符串的幸得@ErikTheGolfer在此评论(与添加的t用于Juliett代替Juliet)。


也许可以使用插值和压缩来减少不存在的单词(trot,tt Kilo,Whiskey Xray)的字节数。混蛋的例子:在线尝试!我以前做过,但是要花很多字,如果您花时间的话,最多可以节省1个字节。
魔术章鱼缸

4

果冻 80  77 字节

ḟ⁶O%32ị“¡µQỤ(cɠṘwlṁ;Ɗœ<NẸ½ṗN¬ṙẋxḶb¤*O~ƃ¹.ß8Ḋ¡tJ|Ḷ<İİḂ^1eȷjċbY9TYƭ¹Ẉ¥¤K0¹f»Ḳ¤

在线尝试!(页脚通过加空格来格式化列表,以避免在作为完整程序运行时隐式粉碎打印)


3

的JavaScript(ES6),181个 189字节

s=>s.match(/\w/g).map(c=>'IndiAlfABravOscaRomeOQuebeCharliEchODeltAGolFoxtroTangOHoteLimAJulietTKilOZulUniforMikENovembeRPapASierrAVictoRWhiskeYankeEXraY'.match(c.toUpperCase()+'.*?[A-Z]'))

由于输出大小写无关紧要,我们可以通过一起运行单词来节省字节:

... GolFoxtroTangO ...

在线尝试!


2

Python 3中250个 191字节

-47个字节感谢@Jo King,-2个感谢@Jonathan Allen

它遍历输入的所有非空格字符,并为每个字母选择与该字母相关的短语,由于每个短语的第一个字母是字符本身,因此可以减少一点。拆分字符串而不是将短语存储为数组以节省不必要的's和,s中的字节。

lambda s:[c+"lfa ravo harlie elta cho oxtrot olf otel ndia uliett ilo ima ike ovember scar apa uebec omeo ierra ango niform ictor hiskey ray ankee ulu".split()[ord(c)%32-1]for c in s if' '<c]

在线尝试!

原始解决方案

lambda s:[c+['lfa','ravo','harlie','elta','cho','oxtrot','olf','otel','ndia','uliett','ilo','ima','ike','ovember','scar','apa','uebec','omeo','ierra','ango','niform','ictor','hiskey','ray','ankee','ulu'][ord(c)-65]for c in s.replace(" ", "").upper()]

在线尝试!


191 withif' '<c
Jonathan Allan

2

210个 193字节

func[s][foreach c trim/all s[prin c print pick[:lfa:ravo:harlie:elta:cho:oxtrot:olf:otel:ndia:uliett:ilo:ima:ike:ovember:scar:apa:uebec:omeo:ierra:ango:niform:ictor:hiskey:ray:ankee:ulu]c% 32]]

在线尝试!

说明:

foreach用删除所有空格后,在字符串上进行迭代trim/allprin打印字符(不换行)。使用映射到范围1..26的字符作为索引printpick从get-word!s(符号)列表中打印一个符号。


2

干净,218字节

import StdEnv
$s=[takeWhile((<=)c)(dropWhile((<)c)['ZuluYankeeXrayWhiskeyVictorUniformTangoSierraRomeoQuebecPapaOscarNovemberMikeLimaKiloJuliettIndiaHotelGolfFoxtrotEchoDeltaCharlieBravoAlfa'])\\c<-map toUpper s|c>' ']

在线尝试!


2

C#(Visual C#交互式编译器),218个字节

n=>n.ToUpper().Select(x=>"AlfaBravoCharlieDeltaEchoFoxtrotGolfHotelIndiaJuliettKiloLimaMikeNovemberOscarPapaQuebecRomeoSierraTangoUniformVictorWhiskeyXrayYankeeZulu".SkipWhile(k=>x!=k).TakeWhile((k,l)=>l<1|k>96&k<123))

在线尝试!

使用Split()的替代版本,194个字节

n=>n.ToUpper().Select(x=>x>64?x+"lfa,ravo,harlie,elta,cho,oxtrot,olf,otel,ndia,uliett,ilo,ima,ike,ovember,scar,apa,uebec,omeo,ierra,ango,niform,ictor,hiskey,ray,ankee,ulu".Split(',')[x%65]:x+"")

在线尝试!


2

C ++,229228字节

[](auto s){for(;auto t=*s?"LfaRavoHarlieEltaChoOxtrotOlfOtelNdiaUliettIloImaIkeOvemberScarApaUebecOmeoIerraAngoNiformIctorHiskeyRayAnkeeUlu":0;s++)if(int c=*s&31){for(cout<<*s;*t>96||--c;t++);for(;cout<<*t,*++t>96;);cout<<' ';}}

在线尝试!

取消高尔夫:

[](const char *s)
{
    const char *table = "LfaRavoHarlieEltaChoOxtrotOlfOtelNdiaUliettIloImaIkeOvemberScarApaUebecOmeoIerraAngoNiformIctorHiskeyRayAnkeeUlu";
    for (; *s; s++)
    {
        char c = *s & 0x1F;
        if (c != 0)
        {
            cout << *s;
            const char *w = table;
            while (*w >= 'a' || --c)
                w++;
            do
                cout << *w;
            while (*++w >= 'a');
            cout << ' ';
        }
    }
}

输出:

TAngo hOtel eCho qUebec uNiform iNdia cHarlie kIlo bRavo rOmeo oScar wHiskey nOvember fOxtrot oScar xRay jUliett uNiform mIke pApa eCho dElta oScar vIctor eCho rOmeo tAngo hOtel eCho lIma aLfa zUlu yAnkee dElta oScar gOlf 
JUliett aLfa cHarlie kIlo dElta aLfa wHiskey sIerra lIma oScar vIctor eCho mIke yAnkee bRavo iNdia gOlf sIerra pApa hOtel iNdia nOvember xRay oScar fOxtrot qUebec uNiform aLfa rOmeo tAngo zUlu 

完全大写的版本(234个字节):

[](auto s){for(;auto t=*s?"LfaRavoHarlieEltaChoOxtrotOlfOtelNdiaUliettIloImaIkeOvemberScarApaUebecOmeoIerraAngoNiformIctorHiskeyRayAnkeeUlu":0;s++)if(int c=*s&31){for(cout<<*s;*t>96||--c;t++);for(;putchar(*t|32),*++t>96;);cout<<' ';}}

在线尝试!

输出:

Tango hotel echo quebec uniform india charlie kilo bravo romeo oscar whiskey november foxtrot oscar xray juliett uniform mike papa echo delta oscar victor echo romeo tango hotel echo lima alfa zulu yankee delta oscar golf 
Juliett alfa charlie kilo delta alfa whiskey sierra lima oscar victor echo mike yankee bravo india golf sierra papa hotel india november xray oscar foxtrot quebec uniform alfa romeo tango zulu 

2

IBM PC DOS 8088机器语言,165字节

这直接基于gwaugh的答案,但是我通过省略$“ NATO”字表中的定界符和不跳过命令行参数字符串的第一个字符(始终为/或, 因此无论如何程序都将忽略它)。该程序最终的长度完全相同,以便能够以这种格式处理表格(其中单词仅由大写字符分隔,这具有兼作每个单词的第二个字母的双重作用)或2个字节如果输出资本化保持与以前相同,则时间更长。该表小26字节。

在下面的程序转储中,:使用by连接来显示与指令对应的连续字节的每个序列:

0000  BE:80:00 AC 91 AC 24:DF 8A:D0 2C:40 3C:1A 77:21  ······$···,@<·w!
0010  8A:F0 B4:02 CD:21 56 BE:34:01 AC A8:20 75:FB FE: ·····!V·4··· u··
0020 :CE 75:F7 8A:D0 CD:21 AC A8:20 75:F7 B2:20 CD:21  ·u····!·· u·· ·!
0030  5E E2:D2 C3 4C 66 61 52 61 76 6F 48 61 72 6C 69  ^···LfaRavoHarli
0040  65 45 6C 74 61 43 68 6F 4F 78 74 72 6F 74 4F 6C  eEltaChoOxtrotOl
0050  66 4F 74 65 6C 4E 64 69 61 55 6C 69 65 74 74 49  fOtelNdiaUliettI
0060  6C 6F 49 6D 61 49 6B 65 4F 76 65 6D 62 65 72 53  loImaIkeOvemberS
0070  63 61 72 41 70 61 55 65 62 65 63 4F 6D 65 6F 49  carApaUebecOmeoI
0080  65 72 72 61 41 6E 67 6F 4E 69 66 6F 72 6D 49 63  erraAngoNiformIc
0090  74 6F 72 48 69 73 6B 65 79 52 61 79 41 6E 6B 65  torHiskeyRayAnke
00A0  65 55 6C 75 40                                   eUlu@

下载DOS NATO.COM可执行文件:
大写字母不正确(165字节)
大写字母不正确(167字节)
奖励版本,每个单词的第一个字母与输入大写相同(167字节)

未组装:

    .MODEL TINY            ; .COM program, maximum addressing space 65536 bytes
    .CODE
    ORG 100h
start:
    MOV  SI, 80h           ; Point SI to DOS PSP (Program Segment Prefix).
    LODSB                  ; Load command-line parameter (input string) length
                           ; into AL; assume AX=0 before this, which is true
                           ; in most versions of DOS; advance SI to first char
                           ; of parameter, which is either '/' or ' '.
    XCHG CX, AX            ; Set up loop counter with length of input string.
search:
    LODSB                  ; Load next character from [SI] into AL; advance SI.
    AND  AL, NOT ('A' XOR 'a')  ; Make this character uppercase.
    MOV  DL, AL            ; Save character for output. Move this before the
                           ; AND instruction to capitalize the first letter of
                           ; each word identically to how it is in the input.
    SUB  AL, 'A'-1         ; convert letter to one-based index (A=1, Z=26, etc)
    CMP  AL, 'Z'-'A'+1     ; Is this an alphabetical character?
    JA   notFound          ; If not, move to next character.
    MOV  DH, AL            ; Set up DH as our word-finding loop counter.
    MOV  AH, 02h           ; AH=02h, INT 21h: Write character to STDOUT
    INT  21h               ; Display first character of this NATO word.
    PUSH SI                ; Save our current position in the input string.
    MOV  SI, OFFSET table  ; Point LODSB to beginning of word data.
scanLoop:                  ; Find the word in the table corresponding to our
                           ; current character.
    LODSB                  ; Load next character from [SI] into AL; advance SI.
    TEST AL, 'A' XOR 'a'   ; Is this character uppercase?
    JNZ  scanLoop          ; If not, move to next character.
    DEC  DH                ; Delimiter (uppercase) found; decrement counter.
    JNZ  scanLoop          ; Keep looping until counter reaches 0.
    OR   AL, 'A' XOR 'a'   ; Make this character lowercase. This is not
                           ; required by the challenge's specification, and
                           ; this instruction can be removed.
wordLoop:
    MOV  DL, AL            ; Display next character from NATO word.
    INT  21h               ; (We still have AH=02h from before.)
    LODSB
    TEST AL, 'A' XOR 'a'   ; Is this character lowercase?
    JNZ  wordLoop          ; If so, continue the loop.
    MOV  DL, ' '           ; Display a space between words.
    INT  21h               ; (We still have AH=02h from before.)
    POP  SI                ; Restore our current position in the input string.
notFound:
    LOOP search            ; Move to next character in input string.
    RET
table   DB  'LfaRavoHarlieEltaChoOxtrotOlfOtelNdia'
        DB  'UliettIloImaIkeOvemberScarApaUebecOmeo'
        DB  'IerraAngoNiformIctorHiskeyRayAnkeeUlu'
        DB  '@'            ; Terminate the list to make sure that uninitialized
                           ; memory doesn't cause a problem.
    END start

输入样例:

>NATO The quick brown fox jumped over the lazy dog.
>NATO Jackdaws love my big sphinx of quartz.

输出(165字节版本):

TAngo hOtel eCho qUebec uNiform iNdia cHarlie kIlo bRavo rOmeo oScar wHiskey nOvember fOxtrot oScar xRay jUliett uNiform mIke pApa eCho dElta oScar vIctor eCho rOmeo tAngo hOtel eCho lIma aLfa zUlu yAnkee dElta oScar gOlf 
JUliett aLfa cHarlie kIlo dElta aLfa wHiskey sIerra lIma oScar vIctor eCho mIke yAnkee bRavo iNdia gOlf sIerra pApa hOtel iNdia nOvember xRay oScar fOxtrot qUebec uNiform aLfa rOmeo tAngo zUlu 

无大写形式(167字节):

Tango Hotel Echo Quebec Uniform India Charlie Kilo Bravo Romeo Oscar Whiskey November Foxtrot Oscar Xray Juliett Uniform Mike Papa Echo Delta Oscar Victor Echo Romeo Tango Hotel Echo Lima Alfa Zulu Yankee Delta Oscar Golf 
Juliett Alfa Charlie Kilo Delta Alfa Whiskey Sierra Lima Oscar Victor Echo Mike Yankee Bravo India Golf Sierra Papa Hotel India November Xray Oscar Foxtrot Quebec Uniform Alfa Romeo Tango Zulu 

大小写纯净的版本,与输入的大小写相同(167字节):

Tango hotel echo quebec uniform india charlie kilo bravo romeo oscar whiskey november foxtrot oscar xray juliett uniform mike papa echo delta oscar victor echo romeo tango hotel echo lima alfa zulu yankee delta oscar golf 
Juliett alfa charlie kilo delta alfa whiskey sierra lima oscar victor echo mike yankee bravo india golf sierra papa hotel india november xray oscar foxtrot quebec uniform alfa romeo tango zulu 

1
那里的工作很好!
640KB

1

木炭,99字节

EΦ↥S№αι⁺ι§⪪”&⌊%w⁸D⦃σν:…ⅈ$|@H¦χT⸿]ECrΣM^¿←←&⁵↘⁼s(JF8X´▷⧴⎚P0V÷AWχπ¶⌈≧\"dJ^ZU{M≔⁴|<¶⁹B⊞⊟1LPH⪪∨Y3`”j⌕αι

在线尝试!链接是详细版本的代码。在适当情况下输出。说明:

   S                    Input string
  ↥                     Uppercased
 Φ                      Filtered where
     α                  Predefined uppercase alphabet
    №                   Contains
      ι                 Current character
E                       Mapped over characters
        ι               Current character
       ⁺                Concatenated with
           ”...”        Compressed string
          ⪪             Split on
                j       Literal string `j`
         §              Indexed by
                 ⌕      Index of
                   ι    Current character
                  α     In uppercase alphabet
                        Implicitly print each word on its own line

1

Perl 6的176个170 166字节

*.comb>>.&{$_~:128[q`>$RbD[Orlo~Q1nX,OVq8x9'6%h'1.I$83ua7	vsD=s-{W}{>iQ:Js37py)hNN,i{Pt\~#f4<>`.ords].base(35).split('J')[.ord%32]}.words

在线尝试!

以大写形式输出,原始大小写中的第一个字母。压缩字符串,仅在较简单的纯文本上节省6个字节:

*.comb>>.&{$_~ <lfa ravo harlie elta cho oxtrot olf otel ndia uliett ilo ima ike ovember scar apa uebec omeo ierra ango niform ictor hiskey ray ankee ulu>[.ord%32-1]if ' 'ne$_}

在线尝试!

说明:

*.comb>>.&{                 }         # Map each letter to
           $_~                        # The letter plus
              <...>[.ord%32]          # The letter indexed into the list of words
                             .words   # And remove the extra spaces

1

Japt,108个 106字节

¸®¬Ë+u cg`ovem¼rws¯r°pawue¼cÙ o±ØǯfmØtØkeyÙ°nkeewªuwlfaæ1ÃÉr¦e³ltawÖoxÉwolfÙ*lÙAawªieâ-¹µ±ke`qw

尝试一下

反引号包含压缩的字符串:

ovemberwscarwapawuebecwomeowierrawangowniformwictorwhiskeywraywankeewuluwlfawravowharlieweltawchowoxtrotwolfwotelwndiawuliettwilowimawike

1

PowerShell187183字节

$args|% t*y|%{'AlfaBravoCharlieDeltaEchoFoxtrotGolfHotelIndiaJuliettKiloLimaMikeNovemberOscarPapaQuebecRomeoSierraTangoUniformVictorWhiskeyXrayYankeeZulu'-csplit'(?=[A-Z])'-like"$_*"}

在线尝试!

测试脚本:

$f = {
$args|% t*y|%{'AlfaBravoCharlieDeltaEchoFoxtrotGolfHotelIndiaJuliettKiloLimaMikeNovemberOscarPapaQuebecRomeoSierraTangoUniformVictorWhiskeyXrayYankeeZulu'-csplit'(?=[A-Z])'-like"$_*"}
}

@(
    ,('Hello World', 'Hotel', 'Echo', 'Lima', 'Lima', 'Oscar', 'Whiskey', 'Oscar', 'Romeo', 'Lima', 'Delta')
) | % {
    $s,$expected = $_
    $result = &$f $s
    "$result"-eq"$expected"
    "$result"
}

输出:

True
Hotel Echo Lima Lima Oscar Whiskey Oscar Romeo Lima Delta

1

PHP209 205 206字节

while($l=$argv[1][$x++])echo$l!=' '?$l.preg_split('/([A-Z][a-z]*)/',ALfaRavoHarlieEltaChoOxtrotOlfOtelNdiaUliettIloImaIkeOvemberScarApaUebecOmeoIerraAngoNiformIctorHiskeyRayAnkeeUlu,0,3)[31&ord($l)].' ':'';

在线尝试!

输出:

"Hello World" => "HOtel eCho lIma lIma oScar WHiskey oScar rOmeo lIma dElta"

195个字节,没有完全删除空格:

while($l=$argv[1][$x++])echo$l,preg_split('/([A-Z][a-z]*)/',ALfaRavoHarlieEltaChoOxtrotOlfOtelNdiaUliettIloImaIkeOvemberScarApaUebecOmeoIerraAngoNiformIctorHiskeyRayAnkeeUlu,0,3)[31&ord($l)].' ';

在线尝试!

输出:

"Hello World" => "HOtel eCho lIma lIma oScar   WHiskey oScar rOmeo lIma dElta"

很好,但是您的最新编辑引入了一个错误。修复它的一种方法是改[31&ord($l)]回它[31&ord($l)-1],花费两个字节,但是您也可以通过完全拼写在一个字节中修复它ALfa
Deadcode '19

哎呀!好的抓手和非常聪明的解决方法。谢谢@deadcode!
640KB

0

TSQL,313字节

打高尔夫球:

DECLARE @ varchar(max)='Hello World' 

DECLARE @x INT=len(@)WHILE @x>0SELECT @=stuff(@,@x,1,substring(@,@x,1)+choose(ascii(substring(@,@x,1))%32,'lfa','eta','harlie','elta','cho','oxtrot','olf','otel','ndia','uliett','ilo','ima','ike','ovember','scar','apa','uebec','omeo','ierra','ango','niform','ictor','hiskey','ray','ankee','ulu')+';'),@x-=1PRINT @

取消高尔夫:

DECLARE @ varchar(max)='Hello World' 

DECLARE @x INT=len(@)
WHILE @x>0
  SELECT @=stuff(@,@x,1,substring(@,@x,1)+choose(ascii(substring(@,@x,1))%32,
    'lfa','eta','harlie','elta','cho','oxtrot','olf','otel','ndia','uliett','ilo',
    'ima','ike','ovember','scar','apa','uebec','omeo','ierra','ango','niform',
    'ictor','hiskey','ray','ankee','ulu')+';'),
    @x-=1

PRINT @

试试看

输出以分号结尾


0

PowerShell,228225字节

-3个字节,感谢@mazzy

"$args".ToLower()-replace' '|% T*y|%{$a+=$_+((-split"lfa ravo harlie elta cho oxtrot olf otel ndia uliett ilo ima ike ovember scar apa uebec omeo ierra ango niform ictor hiskey ray ankee ulu")[('a'..'z').IndexOf($_)])+' '};$a

在线尝试!

这很可能是我编写过的最丑的代码。此外,这当然可以缩短很多时间。为辩护,我仍在从期末考试中恢复。


-split'lfa ravo ...'较短,因为默认情况下'\ s'是分隔

0

PHP,212字节

while($c=ord($argn[$i++]))echo[_,Alpha,Bravo,Charlie,Delta,"Echo",Foxtrot,Golf,Hotel,India,Juliett,Kilo,Lima,Mike,November,Oscar,Papa,Quebec,Romeo,Sierra,Tango,Uniform,Victor,Whiskey,Xray,Yankee,Zulu][$c&31]," ";

与管道一起运行-nR在线尝试

在PHP 7.2中产生警告;将数组元素放在引号中进行修复。

将在空格下划线。


0

C(clang),309字节

#define L toupper(v[1][i])
main(j,v)char**v;{int i=0;char*k[]={"lfa","ravo","harlie","elta","cho","oxtrot","olf","otel","ndia","uliett","ilo","ima","ike","ovember","scar","apa","uebec","omeo","ierra","ango","niform","ictor","hiskey","ray","ankee","ulu"};for(;L;i++)j=L-65,j>=0&j<=26?printf("%c%s ",L,k[j]):0;}

在线尝试!



0

JavaScript,179个字节

s=>s.match(/\w/g).map(c=>c+'LfaRavoHarlieEltaChoOxtrotOlfOtelNdiaUliettIloImaIkeOvemberScarApaUebecOmeoIerraAngoNiformIctorHiskeyRayAnkeeUlu'.match(/.[a-z]+/g)[parseInt(c,36)-10])

在线尝试!

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.