题目描述
从一月份到十二月的英文全称依次是:"January","February","March","April","May","June","July","August","September","October","November","December"
对应的缩写依次是:"Jan.","Feb.","Mar.","Apr.","May.","Jun.","Jul.","Aug.","Sep.","Oct.","Nov.","Dec."。注意首字母大写,后面有个"."
现在用户来输入一个月份的英文,请程序输出对应的英文缩写,无论用户的单词是大写还是小写,均应给出正确的英文缩写。如果输入的英文单词错误,请输出"Error"
例如,用户输入"JULY",程序应输出"Jul."
若用户输入的是"augest",程序应输出"Error"
输入格式
一个英文单词,表示月份
输出格式
对应的月份缩写
分析
将字母全部转换为小写+字符串相等判断
字母全部转换为小写函数
void change(char s[10])
{
int i;
for(i=0;i<10;i++)
{
if(s[i]>='A' && s[i]<='Z')
{
s[i]+=32;
}
}
}
完整代码
#include <stdio.h>
#include <math.h>
#include <string.h>
void change(char s[10])
{
int i;
for(i=0;i<10;i++)
{
if(s[i]>='A' && s[i]<='Z')
{
s[i]+=32;
}
}
}
int main()
{
char mon[12][10]={"january","february","march","april","may","june","july","august","september","october","november","december"};
char suo[12][10]={"Jan.","Feb.","Mar.","Apr.","May,","Jun.","Jul.","Aug.","Sep.","Oct.","Nov.","Dec."};
char s[10];
gets(s);
change(s);
int i;
int c=0;
int flag=0;;
for(i=0;i<12;i++)
{
c=strcmp(s,mon[i]);
if(c==0)
{
flag=1;
printf("%s",suo[i]);
}
}
if(flag==0)
{
printf("Error");
}
return 0;
}