CSS色值
* * * *
拉格朗日计划
* * * *
CSS色值

给定CSS的色值名称,打印出对应的16进制色值,格式为"#RRGGBB",完整的映射表如下:

"IndianRed":            "#cd5c5c",     "LightCoral":      "#f08080",
"Salmon":               "#fa8072",     "DarkSalmon":      "#e9967a",
"LightSalmon":          "#ffa07a",     "Red":             "#ff0000",
"Crimson":              "#dc143c",     "FireBrick":       "#b22222",
"DarkRed":              "#8b0000",     "Pink":            "#ffc0cb",
"LightPink":            "#ffb6c1",     "HotPink":         "#ff69b4",
"DeepPink":             "#ff1493",     "MediumVioletRed": "#c71585",
"PaleVioletRed":        "#db7093",     "Coral":           "#ff7f50",
"Tomato":               "#ff6347",     "OrangeRed":       "#ff4500",
"DarkOrange":           "#ff8c00",     "Orange":          "#ffa500",
"Gold":                 "#ffd700",     "Yellow":          "#ffff00",
"LightYellow":          "#ffffe0",     "LemonChiffon":    "#fffacd",
"LightGoldenRodYellow": "#fafad2",     "PapayaWhip":      "#ffefd5",
"Moccasin":             "#ffe4b5",     "PeachPuff":       "#ffdab9",
"PaleGoldenRod":        "#eee8aa",     "Khaki":           "#f0e68c",
"DarkKhaki":            "#bdb76b",     "Lavender":        "#e6e6fa",
"Thistle":              "#d8bfd8",     "Plum":            "#dda0dd",
"Violet":               "#ee82ee",     "Orchid":          "#da70d6",
"Fuchsia":              "#ff00ff",     "Magenta":         "#ff00ff",
"MediumOrchid":         "#ba55d3",     "MediumPurple":    "#9370db",
"BlueViolet":           "#8a2be2",     "DarkViolet":      "#9400d3",
"DarkOrchid":           "#9932cc",     "DarkMagenta":     "#8b008b",
"Purple":               "#800080",     "Indigo":          "#4b0082",
"DarkSlateBlue":        "#483d8b",     "SlateBlue":       "#6a5acd",
"MediumSlateBlue":      "#7b68ee",     "RebeccaPurple":   "#663399",
"GreenYellow":          "#adff2f",     "Chartreuse":      "#7fff00",
"LawnGreen":            "#7cfc00",     "Lime":            "#00ff00",
"LimeGreen":            "#32cd32",     "PaleGreen":       "#98fb98",
"LightGreen":           "#90ee90",     "SpringGreen":     "#00ff7f",
"MediumSpringGreen":    "#00fa9a",     "MediumSeaGreen":  "#3cb371",
"SeaGreen":             "#2e8b57",     "ForestGreen":     "#228b22",
"Green":                "#008000",     "DarkGreen":       "#006400",
"YellowGreen":          "#9acd32",     "OliveDrab":       "#6b8e23",
"Olive":                "#808000",     "DarkOliveGreen":  "#556b2f",
"MediumAquamarine":     "#66cdaa",     "DarkSeaGreen":    "#8fbc8f",
"LightSeaGreen":        "#20b2aa",     "DarkCyan":        "#008b8b",
"Teal":                 "#008080",     "Aqua":            "#00ffff",
"Cyan":                 "#00ffff",     "LightCyan":       "#e0ffff",
"PaleTurquoise":        "#afeeee",     "Aquamarine":      "#7fffd4",
"Turquoise":            "#40e0d0",     "MediumTurquoise": "#48d1cc",
"DarkTurquoise":        "#00ced1",     "CadetBlue":       "#5f9ea0",
"SteelBlue":            "#4682b4",     "LightSteelBlue":  "#b0c4de",
"PowderBlue":           "#b0e0e6",     "LightBlue":       "#add8e6",
"SkyBlue":              "#87ceeb",     "LightSkyBlue":    "#87cefa",
"DeepSkyBlue":          "#00bfff",     "DodgerBlue":      "#1e90ff",
"CornflowerBlue":       "#6495ed",     "RoyalBlue":       "#4169e1",
"Blue":                 "#0000ff",     "MediumBlue":      "#0000cd",
"DarkBlue":             "#00008b",     "Navy":            "#000080",
"MidnightBlue":         "#191970",     "Cornsilk":        "#fff8dc",
"BlanchedAlmond":       "#ffebcd",     "Bisque":          "#ffe4c4",
"NavajoWhite":          "#ffdead",     "Wheat":           "#f5deb3",
"Burlywood":            "#deb887",     "Tan":             "#d2b48c",
"RosyBrown":            "#bc8f8f",     "SandyBrown":      "#f4a460",
"GoldenRod":            "#daa520",     "DarkGoldenRod":   "#b8860b",
"Peru":                 "#cd853f",     "Chocolate":       "#d2691e",
"SaddleBrown":          "#8b4513",     "Sienna":          "#a0522d",
"Brown":                "#a52a2a",     "Maroon":          "#800000",
"White":                "#ffffff",     "Snow":            "#fffafa",
"Honeydew":             "#f0fff0",     "MintCream":       "#f5fffa",
"Azure":                "#f0ffff",     "AliceBlue":       "#f0f8ff",
"GhostWhite":           "#f8f8ff",     "WhiteSmoke":      "#f5f5f5",
"SeaShell":             "#fff5ee",     "Beige":           "#f5f5dc",
"OldLace":              "#fdf5e6",     "FloralWhite":     "#fffaf0",
"Ivory":                "#fffff0",     "AntiqueWhite":    "#faebd7",
"Linen":                "#faf0e6",     "LavenderBlush":   "#fff0f5",
"MistyRose":            "#ffe4e1",     "Gainsboro":       "#dcdcdc",
"LightGray":            "#d3d3d3",     "LightGrey":       "#d3d3d3",
"Silver":               "#c0c0c0",     "DarkGray":        "#a9a9a9",
"DarkGrey":             "#a9a9a9",     "Gray":            "#808080",
"Grey":                 "#808080",     "DimGray":         "#696969",
"DimGrey":              "#696969",     "LightSlateGray":  "#778899",
"LightSlateGrey":       "#778899",     "SlateGray":       "#708090",
"SlateGrey":            "#708090",     "DarkSlateGray":   "#2f4f4f",
"DarkSlateGrey":        "#2f4f4f",     "Black":           "#000000"


本题难度:



解答

显然应该针对这些名称和色值设计出特定的压缩函数(否则很难想像第一名是如何压缩到615字节的,毕竟就算只把色值或名称输入一遍也需要超过1000个字节)。

不过我不清楚要怎么做,只是简单地作了字符串查找和映射。

最终代码行有两行。

代码长度:2579字节 vs. 全站第一:615字节。

注:本题的难度主要是如何压缩信息。

import sys
for a in sys.argv[1:]:print('#'+'cd5c5c f08080 fa8072 e9967a ffa07a ff0000 dc143c b22222 8b0000 ffc0cb ffb6c1 ff69b4 ff1493 c71585 db7093 ff7f50 ff6347 ff4500 ff8c00 ffa500 ffd700 ffff00 ffffe0 fffacd fafad2 ffefd5 ffe4b5 ffdab9 eee8aa f0e68c bdb76b e6e6fa d8bfd8 dda0dd ee82ee da70d6 ff00ff ff00ff ba55d3 9370db 8a2be2 9400d3 9932cc 8b008b 800080 4b0082 483d8b 6a5acd 7b68ee 663399 adff2f 7fff00 7cfc00 00ff00 32cd32 98fb98 90ee90 00ff7f 00fa9a 3cb371 2e8b57 228b22 008000 006400 9acd32 6b8e23 808000 556b2f 66cdaa 8fbc8f 20b2aa 008b8b 008080 00ffff 00ffff e0ffff afeeee 7fffd4 40e0d0 48d1cc 00ced1 5f9ea0 4682b4 b0c4de b0e0e6 add8e6 87ceeb 87cefa 00bfff 1e90ff 6495ed 4169e1 0000ff 0000cd 00008b 000080 191970 fff8dc ffebcd ffe4c4 ffdead f5deb3 deb887 d2b48c bc8f8f f4a460 daa520 b8860b cd853f d2691e 8b4513 a0522d a52a2a 800000 ffffff fffafa f0fff0 f5fffa f0ffff f0f8ff f8f8ff f5f5f5 fff5ee f5f5dc fdf5e6 fffaf0 fffff0 faebd7 faf0e6 fff0f5 ffe4e1 dcdcdc d3d3d3 d3d3d3 c0c0c0 a9a9a9 a9a9a9 808080 808080 696969 696969 778899 778899 708090 708090 2f4f4f 2f4f4f 000000'.split()['IndianRed LightCoral Salmon DarkSalmon LightSalmon Red Crimson FireBrick DarkRed Pink LightPink HotPink DeepPink MediumVioletRed PaleVioletRed Coral Tomato OrangeRed DarkOrange Orange Gold Yellow LightYellow LemonChiffon LightGoldenRodYellow PapayaWhip Moccasin PeachPuff PaleGoldenRod Khaki DarkKhaki Lavender Thistle Plum Violet Orchid Fuchsia Magenta MediumOrchid MediumPurple BlueViolet DarkViolet DarkOrchid DarkMagenta Purple Indigo DarkSlateBlue SlateBlue MediumSlateBlue RebeccaPurple GreenYellow Chartreuse LawnGreen Lime LimeGreen PaleGreen LightGreen SpringGreen MediumSpringGreen MediumSeaGreen SeaGreen ForestGreen Green DarkGreen YellowGreen OliveDrab Olive DarkOliveGreen MediumAquamarine DarkSeaGreen LightSeaGreen DarkCyan Teal Aqua Cyan LightCyan PaleTurquoise Aquamarine Turquoise MediumTurquoise DarkTurquoise CadetBlue SteelBlue LightSteelBlue PowderBlue LightBlue SkyBlue LightSkyBlue DeepSkyBlue DodgerBlue CornflowerBlue RoyalBlue Blue MediumBlue DarkBlue Navy MidnightBlue Cornsilk BlanchedAlmond Bisque NavajoWhite Wheat Burlywood Tan RosyBrown SandyBrown GoldenRod DarkGoldenRod Peru Chocolate SaddleBrown Sienna Brown Maroon White Snow Honeydew MintCream Azure AliceBlue GhostWhite WhiteSmoke SeaShell Beige OldLace FloralWhite Ivory AntiqueWhite Linen LavenderBlush MistyRose Gainsboro LightGray LightGrey Silver DarkGray DarkGrey Gray Grey DimGray DimGrey LightSlateGray LightSlateGrey SlateGray SlateGrey DarkSlateGray DarkSlateGrey Black'.split().index(a)])