10、实现中英文的转换,输入汉语星期几,输出该星期的英文名。可以用指针数组处理字符串。C语言

如题所述

int issame(char all[][10],char* n)
{
int bz = 0;
for(int i = 0;i < 7;++i)
{
int j = 0;

while(n[j])
{
if(all[i][j] != n[j])
break;
j++;
}
if(all[i][j] == n[j] && n[j] == 0)
bz = 1;
if(bz)
return i;
}
return -1;
}

int main()
{
char chinese[7][10] = {"星期一","星期二","星期三","星期四","星期五","星期六","星期日",};
char english[7][10] = {"Mon","Tus","Wek","Thu","Fri","Sar","Sun"};
char nowcin[10];
int i = -1;
while (i == -1)
{
std::cin>>nowcin;
i = issame(chinese,nowcin);
}
std::cout<<english[i]<<std::endl;
system("pause");
}
温馨提示:答案为网友推荐,仅供参考