c++论坛吧 关注:48贴子:128
  • 1回复贴,共1

摩尔斯电码转换器C++代码

只看楼主收藏回复

#include<iostream>
using namespace std;
int main()
{
cout << "欢迎使用摩尔斯电码转换器" << endl;
cout << "请问您要翻译几个单词" << endl;
int l = 0;
cin >> l;
for (int j = 1; j < l + 1; j++)
{
cout << "请问您第" << j << "个要翻译的单词有多少个字母" << endl;
int a = 0;
cin >> a;
char arr[100];
for (int i = 1; i < 101; i++)
{
if (i - 1 == a)
{
break;
}
cout << "请输入第" << i << "个字符" << endl;
cin >> arr[i - 1];
}
for (int j = 0; j < 100; j++)
{
if (j == a)
{
break;
}
if (arr[j] == 'a')
{
cout << "*-";
}
if (arr[j] == 'b')
{
cout << "-***";
}
if (arr[j] == 'c')
{
cout << "-*-*";
}
if (arr[j] == 'd')
{
cout << "-**";
}
if (arr[j] == 'e')
{
cout << "*";
}
if (arr[j] == 'f')
{
cout << "**-*";
}
if (arr[j] == 'g')
{
cout << "--*";
}
if (arr[j] == 'h')
{
cout << "****";
}
if (arr[j] == 'i')
{
cout << "**";
}
if (arr[j] == 'j')
{
cout << "*---";
}
if (arr[j] == 'k')
{
cout << "-*-";
}
if (arr[j] == 'l')
{
cout << "*-**";
}
if (arr[j] == 'm')
{
cout << "--";
}
if (arr[j] == 'n')
{
cout << "-*";
}
if (arr[j] == 'o')
{
cout << "---";
}
if (arr[j] == 'p')
{
cout << "*--*";
}
if (arr[j] == 'q')
{
cout << "--*-";
}
if (arr[j] == 'r')
{
cout << "*-*";
}
if (arr[j] == 's')
{
cout << "***";
}
if (arr[j] == 't')
{
cout << "-";
}
if (arr[j] == 'u')
{
cout << "**-";
}
if (arr[j] == 'v')
{
cout << "***-";
}
if (arr[j] == 'w')
{
cout << "*--";
}
if (arr[j] == 'x')
{
cout << "-**-";
}
if (arr[j] == 'y')
{
cout << "-*--";
}
if (arr[j] == 'z')
{
cout << "--**";
}
cout << "/";
}
cout << endl;
}
system("pause");
return 0;
}


IP属地:浙江1楼2021-07-19 09:02回复
    谁有办法可以优化代码,请多多指教


    IP属地:浙江2楼2021-07-19 09:04
    回复