首页 > 试题广场 >

HTTP状态码

[编程题]HTTP状态码
  • 热度指数:29889 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解

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
#include <stdio.h>
int main() {
    int a;
   
    while ((scanf("%d", &a)) != EOF)
    {
    if (a==200)
    {
        printf("OK\n");
    }
    if (a==202)
    {
        printf("Accepted\n");
    }
        if (a==400)
    {
        printf("Bad Request\n");
    }
        if (a==403)
    {
        printf("Forbidden\n");
    }
        if (a==404)
    {
        printf("Not Found\n");
    }
        if (a==500)
    {
        printf("Internal Server Error\n");
    }
        if (a==502)
    {
        printf("Bad Gateway\n");
    }
    }
    return 0;
}
发表于 2024-09-22 13:34:55 回复(0)
#include <stdio.h>

int main() {
    int a = 0;
    while((scanf("%d",&a))!=EOF)
    {
        if ( a==200 )
            printf("OK\n");
        else if ( a ==202 )
            printf("Accepted\n");
        else if ( a ==400 )
            printf("Bad Request\n");
        else if ( a == 403 )
            printf("Forbidden\n");
        else if ( a ==404 )
            printf("Not Found\n");
        else if ( a== 500 )
            printf("Internal Server Error\n");
        else if ( a == 502 )
            printf("Bad Gateway\n");
        else
            printf("输入HTTP码有误,请重新输入\n");
    }
    return 0;
}

发表于 2024-08-02 00:24:39 回复(0)
#include <stdio.h>

int main() {
    int i = 0;
    while (scanf("%d", &i) != EOF) {
        switch (i) {
            case 200:
                printf("OK\n");
                break;
            case 202:
                printf("Accepted\n");
                break;
            case 400:
                printf("Bad Request\n");
                break;
            case 403:
                printf("Forbidden\n");
                break;
            case 404:
                printf("Not Found\n");
                break;
            case 500:
                printf("Internal Server Error\n");
                break;
            case 502:
                printf("Bad Gateway\n");
                break;
        }
    }
    // }while(i==502?0:1);     //当i = 502时,就会跳出循环,“错误网关”
    return 0;
}

发表于 2024-04-18 18:14:41 回复(0)
#include <stdio.h>

enum
{
    OK = 200,
    Accepted = 202,
    BadRequest = 400,
    Forbidden = 403,
    NotFound = 404,
    InternalServerError = 500,
    BadGateway = 502
};

int main() 
{
    int num = 0;
    int i = 0;
            
    while(scanf("%d", &num) != EOF)
    {
        switch(num)
        {
            case OK:
            printf("OK\n");
            break;
            case Accepted:
            printf("Accepted\n");
            break;
            case BadRequest:
            printf("Bad Request\n");
            break;
            case Forbidden:
            printf("Forbidden\n");
            break;
            case NotFound:
            printf("Not Found\n");
            break;
            case InternalServerError:
            printf("Internal Server Error\n");
            break;
            case BadGateway:
            printf("Bad Gateway\n");
            break;
            default:
            printf("输入错误\n");
            break;
        }
    }

    return 0;
}

发表于 2024-03-19 13:39:13 回复(0)
#include <stdio.h>

int main() {
    int a;
    while(scanf("%d", &a) != EOF){
        switch (a) {
            case 200:printf("OK\n");break;
            case 202:printf("Accepted\n");break;
            case 400:printf("Bad Request\n");break;
            case 403:printf("Forbidden\n");break;
            case 404:printf("Not Found\n");break;
            case 500:printf("Internal Server Error\n");break;
            case 502:printf("Bad Gateway\n");break;
        }
    }
    return 0;
}
编辑于 2024-01-16 12:55:01 回复(0)
#include <stdio.h>

int main() {
    int n = 0;
    while (scanf("%d", &n) != EOF) {
        switch (n) {
            case 200:
                printf("OK\n");
                break;
            case 202:
                printf("Accepted\n");
                break;
            case 400:
                printf("Bad Request\n");
                break;
            case 403:
                printf("Forbidden\n");
                break;
            case 404:
                printf("Not Found\n");
                break;
            case 500:
                printf("Internal Server Error\n");
                break;
            case 502:
                printf("Bad Gateway\n");
                break;
        }
    }
    return 0;
}

编辑于 2024-01-10 10:59:40 回复(0)
#include <stdio.h>

int main() {
    int n = 0;
    while (scanf("%d", &n)!=EOF) 
    {
        switch (n) 
        {
            case 200:
                printf("OK\n");
                break;
            case 202:
                printf("Accepted\n");
                break;
            case 400:
                printf("Bad Request\n");
                break;
            case 403:
                printf("Forbidden\n");
                break;
            case 404:
                printf("Not Found\n");
                break;
            case 500:
                printf("Internal Server Error\n");
                break;
            case 502:
                printf("Bad Gateway\n");
                break;
            default:
                printf("输入错误\n");
                break;
        }
    }
    return 0;
}

发表于 2023-11-05 21:57:33 回复(0)
#include <stdio.h>

int main() {
    int n = 0;
    while (scanf("%d", &n) != EOF) {
        switch (n) {
            case 200:
                printf("OK\n");
                break;
            case 202:
                printf("Accepted\n");
                break;
            case 400:
                printf("Bad Request\n");
                break;
            case 403:
                printf("Forbidden\n");
                break;
            case 404:
                printf("Not Found\n");
                break;
            case 500:
                printf("Internal Server Error\n");
                break;
            case 502:
                printf("Bad Gateway\n");
                break;
        }
    }
    return 0;
}

发表于 2023-03-13 22:48:32 回复(0)
#include <stdio.h>

int main() {
    int http = 0;
    while(scanf("%d", &http) != EOF)
    {
        switch(http)
        {
            case 200 : printf("OK\n");
            break;
            case 202 : printf("Accepted\n");
            break;
            case 400 : printf("Bad Request\n");
            break;
            case 403 : printf("Forbidden\n");
            break;
            case 404 : printf("Not Found\n");
            break;
            case 500 : printf("Internal Server Error\n");
            break;
            case 502 : printf("Bad Gateway");
            break;
        }
    }

    return 0;
}
发表于 2023-02-26 23:26:38 回复(0)
#include <stdio.h>
int main() {
    int HTTPstatus;
    while (scanf("%d", &HTTPstatus) != EOF) {
        switch (HTTPstatus) {
            case 200:
                printf("OK\n");
                break;
            case 202:
                printf("Accepted\n");
                break;
            case 400:
                printf("Bad Request\n");
                break;
            case 403:
                printf("Forbidden\n");
                break;
            case 404:
                printf("Not Found\n");
                break;
            case 500:
                printf("Internal Server Error\n");
                break;
            case 502:
                printf("Bad Gateway\n");
                break;
            default:
                printf("Invalid Inpu!!!\n");
                break;
        }

    }
    return 0;
}
发表于 2023-02-15 01:12:03 回复(0)
#include <stdio.h>
int main() {
int http=0;
while((scanf("%d",&http))!=EOF){
http==200?printf("OK\n"):http==202?printf("Accepted\n"):http==400?printf("Bad Request\n"):http==403?printf("Forbidden\n"):http==404?printf("Not Found\n"):http==500?printf("Internal Server Error\n"):http==502?printf("Bad Gateway\n"):0;}
}

发表于 2022-10-25 12:19:04 回复(0)
#include<stdio.h>
int main()
{
    int a;
    while (scanf("%d",&a) != EOF)
    switch(a)
    {
        case 200:
            printf("OK\n");
            break;
        case 202:
              printf("Accepted\n");
            break;
        case 400:
            printf("Bad Request\n");
            break;
        case 403:
            printf("Forbidden\n");
            break;
        case 404:
            printf("Not Found\n");
            break;
        case 500:
            printf("Internal Server Error\n");
            break;
        case 502:
            printf("Bad Gateway\n");
            break;
        default:
            break;            
    }     
    return 0;
}

发表于 2022-09-02 21:38:50 回复(0)
#include<stdio.h>
int main()
{
    int http = 0;
    while (scanf("%d",&http) != EOF)
        switch(http)
        {
            case 200:
                printf("OK\n");
                break;
            case 202:
                printf("Accepted\n");
                break;
            case 400:
                printf("Bad Request\n");
                break;
            case 403:
                printf("Forbidden\n");
                break;
            case 404:
                printf("Not Found\n");
                break;
            case 500:
                printf("Internal Server Error\n");
                break;
            case 502:
                printf("Bad Gateway\n");
                break;
            default:
                break;
        }
    return 0;
}

发表于 2022-08-25 20:17:18 回复(0)
#include<stdio.h>
int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        if(n==200){
            printf("OK\n");
        }
        else if (n==202){
            printf("Accepted\n");
        }
        else if (n==400){
            printf("Bad Request\n");
        }
        else if (n==403){
            printf("Forbidden\n");
        }
        else if (n==404){
            printf("Not Found\n");
        }
        else if (n==500){
            printf("Internal Server Error\n");
        }
        else 
            printf("Bad Gateway");
    }
}
发表于 2022-07-19 11:15:13 回复(0)
#include <stdio.h>
int main()
{
    int n;
    while(scanf("%d", &n) != EOF)
    {
        switch(n)
        {
            case 200 :
                printf("OK\n");
                break;
            case 202 :
                printf("Accepted\n");
                break;
            case 400 :
                printf("Bad Request\n");
                break;
            case 403 :
                printf("Forbidden\n");
                break;
            case 404 :
                printf("Not Found\n");
                break;
            case 500 :
                printf("Internal Server Error\n");
                break;
            case 502 :
                printf("Bad Gateway\n");
                break;
        }
    }
    return 0;
}

发表于 2022-06-27 19:25:45 回复(0)
#include<stdio.h>
int main()
{
    int a;
    while((scanf("%d",&a))!=EOF)
    {
        switch(a)
        {
            case 200:
                printf("OK");
                break;
            case 202:
                printf("Accepted");
                break;
            case 400:
                printf("Bad Request");
                break;
            case 403:
                printf("Forbidden");
                break;
            case 404:
                printf("Not Found");
                break;
            case 500:
                printf("Internal Server Error");
                break;
            case 502:
                printf("Bad Gateway");
                break;
        }
        printf("\n");
    }
}

发表于 2022-06-27 14:44:46 回复(0)
#include <stdio.h>

int main(){
    typedef struct {
        int num;
        char arr[30];
    } httpmap;
    
    httpmap arr[7] = {{200, "OK"}, {202, "Accepted"}, {400, "Bad Request"}, {403, "Forbidden"},
                     {404, "Not Found"}, {500, "Internal Server Error"}, {502, "Bad Gateway"}};
    int num = 0;
    while(scanf("%d", &num) != EOF){
        getchar();
        for(int i = 0; i < 7; i++){
            if(arr[i].num == num)
                printf("%s\n", arr[i].arr);
          }
    }
    return 0;
}

发表于 2022-05-22 21:29:57 回复(0)
#include<stdio.h>
int main()
{
    int a;
    scanf("%d",&a);
    switch(a)
    {
        case 200:printf("OK\n");
        case 202:printf("Accepted\n");    
        case 400:printf("Bad Request\n");    
        case 403:printf("Forbidden\n");
        case 404:printf("Not Found\n");
        case 500:printf("Internal Server Error\n");
        case 502:printf("Bad Gateway\n");
    }
    return 0;
}
发表于 2022-03-09 21:39:04 回复(0)
#include<stdio.h>
int main()
{
    //法一
    /*
    int arr[7]={200,202,400,403,404,500,502};
    int i;
    for(i=0;i<7;i++)
    {
       scanf("%d\n",&arr[i]);
    switch(arr[i])
    {
        case 200:printf("OK\n");
            break;
        case 202:printf("Accepted\n");
            break;
        case 400:printf("Bad Request\n");
            break;
        case 403:printf("Forbidden\n");
            break;
        case 404:printf("Not Found\n");
            break;
        case 500:printf("Internal Server Error\n");
            break;
        case 502:printf("Bad Gateway\n");
            break;
    }
    }
    */
    //法二
    int n;
   while((scanf("%d",&n))!=EOF)
   {
    switch(n)
    {
        case 200:printf("OK\n");
            break;
        case 202:printf("Accepted\n");
            break;
        case 400:printf("Bad Request\n");
            break;
        case 403:printf("Forbidden\n");
            break;
        case 404:printf("Not Found\n");
            break;
        case 500:printf("Internal Server Error\n");
            break;
        case 502:printf("Bad Gateway\n");
            break;
    }
   }
    
    return 0;
}

发表于 2022-03-08 16:46:06 回复(0)