C++で特定の文字を数字に変換し、それ以外の文字はそのままにして、入力された文字列を変換し、出力するプログラムを作りたいのですが、このコードの何がいけないのでしょうか。
#include <iostream>
#include <string>
using namespace std;
int main()
{
string a;
string b;
int c;
cin>>a;
c=a.size();
while(0<c){if (a.substr(0)=="A") b=b+="4",a.erase(a.begin() +0 ),c-1;else if (a.substr(0)=="E")b=b+="3",a.erase(a.begin() +0 ),c-1;else if (a.substr(0)=="G")b=b+="6",a.erase(a.begin() +0 ),c-1;else if (a.substr(0)=="I")b=b+="1",a.erase(a.begin() +0 ),c-1;else if (a.substr(0)=="O")b=b+="0",a.erase(a.begin() +0 ),c-1;else if (a.substr(0)=="S")b=b+="5",a.erase(a.begin() +0 ),c-1;else if (a.substr(0)=="Z")b=b+="2",a.erase(a.begin() +0 ),c-1;else b=b+=a.substr(0),a.erase(a.begin() +0),c-1;}
cout<<b<<endl;
return 0;
}
汚くてもうしわけありません。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/06/05 11:23
2016/06/05 12:48