多边形前缀


17

多边形是根据多边形的边数命名的。五边形具有5个边,八边形具有8个边。但是,它们如何命名?248面多边形的名称是什么?

所有多边形后缀为-gon。每个多边形都有特定的前缀,具体取决于边数。以下是较低数字的前缀:

3 - tri
4 - tetra
5 - penta
6 - hexa
7 - hepta
8 - octa
9 - nona
10 - deca
11 - undeca
12 - dodeca
13 - triskaideca
14 - tetradeca
15 - pentadeca
16 - hexadeca
17 - heptadeca
18 - octadeca
19 - nonadeca
20 - icosa

边数为21到99的多边形具有不同的系统。取十位数的前缀(在左列中找到)和一个位数(在下面的右列中),然后在它们之间插入一个“ kai”以获得(tens)kai(ones)gon

10 - deca        | 1 - hena
20 - icosi       | 2 - di
30 - triaconta   | 3 - tri
40 - tetraconta  | 4 - tetra
50 - pentaconta  | 5 - penta
60 - hexaconta   | 6 - hexa
70 - heptaconta  | 7 - hepta
80 - octaconta   | 8 - octa
90 - nonaconta   | 9 - nona

三位数的多边形以类似的方式命名。一个100面的多边形称为十六边形。取几百位数,在列上找到一位数字,然后在其右侧粘贴一个“ hecta”。现在从十位数开始减少数字,如上:(hundreds)hecta(tens)kai(ones)gon。如果百位数字是1,请不要在“ hecta”后面加上前缀;如果一个位置为0,则省略(一个)部分。

因此,给定一个整数(3 <= n <= 999),返回n边多边形的名称。n-gon不是有效的答案:P

与所有代码高尔夫一样,最短的代码获胜。


100面是六角形还是六角形?高于100的十位数也不清楚。我猜110和120是hectahenakaigon和hectadikaigon(或hectaicosikaigon?)
ugoren 2013年

另外,从101面看是“ hectakaihenagon”(据我从您的规则中了解)还是“ hectahenagon”?
ugoren

@ beary605我认为nona-是错误的。那将来自拉丁语,而其他的七,六则来自希腊。应该是ennea-。我知道维基百科说nagon可以!
felipa

@felipa:我正在讨论是否要使用它ennea-,但是我比“ enneagon”更经常听到“ nonagon”,所以我同意了。
beary605

@ugoren:100-公顷,我没有发现我没有deca,谢谢。110-八角形,120-六角形。101-hectakaihenagon。
beary605

Answers:


5

C,401,391

让我们把东西放在那里,以便至少有一个答案供参考:-)

char*s[]={"","hena","di","tri","tetra","penta","hexa","hepta","octa","nona","un","do","triskai","deca","icosi","tria","conta","kai","icosa","hecto","hecta","gon\n"};
p(i){printf(s[i]);}
t;n(i){
    if(i<10)
        p(i);   // ones
    else if(i<20){
        i-=10; 
        p(i+(i&&i<4)*9); // teens
        p(13); // "deca"
    }else if(i==20)
        p(18); // "icosa"
    else if(i==100)
        p(19); // "hecto"
    else{
        t=i/100;
        p(t>1?t:0); // hundreds
        p(t?20:0);  // "hecta"
        i%=100;
        t=i/10;
        p(t+(t&&t<4)*12); // tens
        p(t>2?16:0);      // "conta"
        i%=10;
        p(i?17:0); // "kai"
        p(i);      // ones
    }
    p(21); // "gon\n"
}

测试:

main(){
    for(int i=3;i<=999;i++){
        printf("%3d: ",i);n(i);
    }
}

输出子集:

  3: trigon
  4: tetragon
  5: pentagon
  6: hexagon
  7: heptagon
  8: octagon
  9: nonagon
 10: decagon
 11: undecagon
 12: dodecagon
 13: triskaidecagon
 14: tetradecagon
 15: pentadecagon
 16: hexadecagon
 17: heptadecagon
 18: octadecagon
 19: nonadecagon
 20: icosagon
 21: icosikaihenagon
 22: icosikaidigon
 23: icosikaitrigon
...
 99: nonacontakainonagon
100: hectogon
101: hectakaihenagon
102: hectakaidigon
103: hectakaitrigon
104: hectakaitetragon
105: hectakaipentagon
106: hectakaihexagon
107: hectakaiheptagon
108: hectakaioctagon
109: hectakainonagon
110: hectadecagon
111: hectadecakaihenagon
...
997: nonahectanonacontakaiheptagon
998: nonahectanonacontakaioctagon
999: nonahectanonacontakainonagon

1
真好 您可以if..else?:(和;替换,)来保存一些字符。同样t>1&&p(t),类似的更改也可以提供帮助。而且我不确定,但是也许您可以重新排列,s以便您使用的常数为个位数。
ugoren

1

JavaScript的- 405 386

版本1:(405个字符)

i=prompt(),o='0hena0di0tri0tetra0penta0hexa0hepta0octa0nona'.split(0),d='0W0icosi0triaQ0tetraQ0pentaQ0hexaQ0heptaQ0octaQ0nonaQ'.split(0),t='W0unW0doW0triskaiW0tetraW0pentaW0hexaW0heptaW0octaW0nonaW0icosa'.split(0),x=('000'+i).substr(-3).split('');alert((i<10?o[i]:i<21?t[i-10]:i==100?'hecto':(i<100?'':i<200?'hecta':o[x[0]]+'hecta')+d[x[1]]+'kai'+o[x[2]]).replace(/Q/g,'conta').replace(/W/g,'deca')+'gon')

版本2:(386个字符)

i=prompt(),p='0tetra0penta0hexa0hepta0octa0nona',o='0hena0di0tri'+p,t=('W0unW0doW0triskai'+p.replace(/0/g,'W0')+'W0icosa').split(0),x=('000'+i).substr(-3).split(''),o=o.split(0);alert((i<10?o[i]:i<21?t[i-10]:i==100?'hecto':(i<100?'':i<200?'hecta':o[x[0]]+'hecta')+('0W0icosi0tria'+p.replace(/0/g,'Q0')+'Q').split(0)[x[1]]+'kai'+o[x[2]]).replace(/Q/g,'conta').replace(/W/g,'deca')+'gon')

输出示例:

3: trigon
4: tetragon
5: pentagon
6: hexagon
7: heptagon
8: octagon
9: nonagon
10: decagon
11: undecagon
12: dodecagon
13: triskaidecagon
14: tetradecagon
15: pentadecagon
16: hexadecagon
17: heptadecagon
18: octadecagon
19: nonadecagon
20: icosagon
21: icosikaihenagon
22: icosikaidigon
23: icosikaitrigon
99: nonacontakainonagon
...
100: hectogon
101: hectakaihenagon
102: hectakaidigon
103: hectakaitrigon
104: hectakaitetragon
105: hectakaipentagon
106: hectakaihexagon
107: hectakaiheptagon
108: hectakaioctagon
109: hectakainonagon
110: hectadecakaigon
111: hectadecakaihenagon
...
997: nonahectanonacontakaiheptagon
998: nonahectanonacontakaioctagon
999: nonahectanonacontakainonagon 

0

眼镜蛇-370字节

当前是一个函数,但是如果不允许,那么我将对其进行更改。

def f(x) as String
    o='. hena di tri tetra penta hexa hepta octa nona'.split
    o[0],t,h,d='',['','deca','icosci','triconta'],['','hecta','dihecta','trihecta'],['undeca','dodeca','triskaideca']
    for z in 4:10,t,h,d=t+[o[z]+'conta'],h+[o[z]+'hecta'],d+[o[z]+'deca']
    for z in 10,t[z]+='kai'
    return if(x-100,h[x//100]+if(10<x<20,d[x-11],t[x%100//10]+o[x%10]),'hecto')+'gon'

由于某种原因,眼镜蛇荧光笔已//设置为注释,这是错误的。

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.