一次做ACM扩展出来的小程序

来源:互联网 发布:peta 知乎 编辑:程序博客网 时间:2024/04/29 17:47

这个小程序就是自己学习用的
第一次实践式的写一个程序,纪念一下,哈哈~~

程序功能描述:
0 - “_”
1 - “a”
2 - “b”
……….
25 - “y”
26 - “z”
27 - “.”

可以互相进行查询

#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){    int i, j = 0, length, code[28];    char str[1000];    //对code数组按照要求赋值    //"_" ASCII value is 95    //"." ASCII value is 46    //"a" ASCII valude is 97    code[0] = '_';    code[27] = '.';    for(i = 1; i < 27; i++)    {        code[i] = 'a' + i - 1;    }    printf("PS: \"-1\" means END!!\n");    printf("Please input the num or letter:<0-27 | a-z | \"_\"| \".\" only>\n");    while(scanf("%s", str))    {        length = strlen(str);        if(length == 1)        {            if((str[0] < 'a' || str[0] > 'z') && str[0] != '_' && str[0] != '.' && (str[0] < '0' || str[0] > '9'))            {                printf("Input Error! Input again:\n");            }            else            {                for(i = 0; ; i++)                {                    //char型数据处理                    if((str[0] - 'a') >= 0)                    {                        if(code[i] == str[0])                        {                            printf("The %c is %d\n", str[0], i);                            break;                        }                    }                    else if(str[0] == '_' || str[0] == '.')                    {                        if(str[0] == '_')                        {                            printf("The _ is %d\n", 0);                            break;                        }                        else if(str[0] == '.')                        {                            printf("The . is %d\n", 27);                            break;                        }                    }                    //int型数据处理                    else if(i == atoi(str))                    {                        printf("The %d is %c\n", i, code[i]);                        break;                    }                }            }        }        else if(length == 2)        {            //先处理正确的            //            //            //int型的两位数处理            if(((atoi(str) - 10) >= 0) && ((atoi(str) - 27) <= 0) && atoi(str) != -1)            {                for(i = 10; ; i++)                {                    if(i == atoi(str))                    {                        printf("The %d is %c\n", i, code[i]);                        break;                    }                }            }            else if(atoi(str) == -1)            {                printf("The program ENDED!!\n");                return 0;            }            else            {                printf("Input Error! Input again!\n");            }        }        else        {            printf("Input Error! Input again!\n");        }    }    return 0;}
0 0
原创粉丝点击