[問題] 字串處理
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
DEV-C++
問題(Question):
題目主要是說 每個電話號碼可以對應到三個英文字母(程式尚未完成)
但在字串處理上碰到一些問題
就是在i以後的字串 都會多印很多個字元
不知道是什麼問題 麻煩解答一下 謝謝!
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <iostream>
#include <string>
using namespace std;
int main()
{
char *number[10]={"0","0","ABC","DEF","GHI","JKL","MNO","PRS","TUV","WXY"};
int in,phone[7];
int a,b,c,d,e,f,g;
int w;
char h[3],i[3],j[3],k[3],l[3],m[3],n[3];
cout<<"Please enter the phone number";
cin>>in;
for(w=6;w>=0;w--)
{
phone[w]=in%10;
in=in/10;
}
for(w=0;w<=2;w++)
{
h[w]=*number[phone[0]]+w;
i[w]=*number[phone[1]]+w;
j[w]=*number[phone[2]]+w;
k[w]=*number[phone[3]]+w;
l[w]=*number[phone[4]]+w;
m[w]=*number[phone[5]]+w;
n[w]=*number[phone[6]]+w;
}
cout<<h<<i<<j<<k<<l<<m<<n;
system("Pause");
return 0;
}
補充說明(Supplement):
這是螞蟻本內的題目 第七版的8.11題
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.115.200.8
→
12/20 07:33, , 1F
12/20 07:33, 1F
→
12/20 07:56, , 2F
12/20 07:56, 2F
→
12/20 07:56, , 3F
12/20 07:56, 3F
所以要怎麼結束才好??
※ 編輯: o3208 來自: 140.115.200.8 (12/20 11:55)
→
12/20 16:39, , 4F
12/20 16:39, 4F
→
12/21 01:12, , 5F
12/21 01:12, 5F
感謝,已解決!
※ 編輯: o3208 來自: 140.115.200.8 (12/21 02:49)
→
12/21 09:04, , 6F
12/21 09:04, 6F
討論串 (同標題文章)