NC22095. HTTP状态码
描述
KiKi访问网站,得到HTTP状态码,但他不知道什么含义,BoBo老师告诉他常见HTTP状态码:200(OK,请求已成功),202(Accepted,服务器已接受请求,但尚未处理。)400(Bad Request,请求参数有误),403(Forbidden,被禁止),404(Not Found,请求失败),500(Internal Server Error,服务器内部错误),502(Bad Gateway,错误网关)。
输入描述
多组输入,一行,一个整数(100~600),表示HTTP状态码。
输出描述
针对每组输入的HTTP状态,输出该状态码对应的含义,具体对应如下:
200-OK
202-Accepted
400-Bad Request
403-Forbidden
404-Not Found
500-Internal Server Error
502-Bad Gateway
示例1
输入:
200
输出:
OK
C++11(clang++ 3.9) 解法, 执行用时: 3ms, 内存消耗: 356K, 提交时间: 2020-06-03 19:42:06
#include<bits/stdc++.h> using namespace std; map<int,string>m; int main(){ m[200]="OK"; m[202]="Accepted"; m[400]="Bad Request"; m[403]="Forbidden"; m[404]="Not Found"; m[500]="Internal Server Error"; m[502]="Bad Gateway"; int n; while(cin>>n){ cout<<m[n]<<endl; } }
C++14(g++5.4) 解法, 执行用时: 4ms, 内存消耗: 460K, 提交时间: 2020-06-03 19:56:29
#include<iostream> using namespace std; int main() { string a[503]; a[200]="OK",a[202]="Accepted",a[400]="Bad Request",a[403]="Forbidden"; a[404]="Not Found",a[500]="Internal Server Error",a[502]="Bad Gateway"; int n; while(cin>>n) { cout<<a[n]<<endl; } }
C(clang 3.9) 解法, 执行用时: 2ms, 内存消耗: 256K, 提交时间: 2019-11-10 20:48:36
#include<stdio.h> int main() { int a; while(~scanf("%d",&a)) printf("%s\n",a==200?"OK":a==202?"Accepted":a==400?"Bad Request":a==403?"Forbidden":a==404?"Not Found":a==500?"Internal Server Error":a==502?"Bad Gateway":"\n"); }
Python3(3.5.2) 解法, 执行用时: 23ms, 内存消耗: 3324K, 提交时间: 2020-06-03 19:33:56
import sys for s in sys.stdin:print({"200":"OK","202":"Accepted","400":"Bad Request","403":"Forbidden","404":"Not Found","500":"Internal Server Error","502":"Bad Gateway"}.get(s[:-1]))
pypy3(pypy3.6.1) 解法, 执行用时: 70ms, 内存消耗: 19184K, 提交时间: 2020-06-05 01:01:43
import sys for s in sys.stdin:print({200:"OK",202:"Accepted",400:"Bad Request",403:"Forbidden",404:"Not Found",500:"Internal Server Error",502:"Bad Gateway"}[int(s)])