#448: 請求協助 我搞不懂


shadowevor (ShadowEvor)

學校 : 臺北市立建國高級中學
編號 : 2286
來源 : [59.117.213.125]
最後登入時間 :
2008-10-16 21:53:16
a008. 中文大寫數字 -- admin | From: [218.161.48.210] | 發表日期 : 2008-08-06 11:20

我是c++的初學者

字串的東西不太清楚

能夠麻煩幫我debug看看嗎?(我不知道問題在哪)

只要輸入就當掉(問題很大)

 

程式碼滿有點亂請見諒

 

#include <cstdlib>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
string numturn(int num)
{
       switch(num) {
                   case 1:
                        return("壹");
                   case 2:
                        return("貳");
                   case 3:
                        return("參");
                   case 4:
                        return("肆");
                   case 5:
                        return("伍");
                   case 6:
                        return("陸");
                   case 7:
                        return("柒");
                   case 8:
                        return("捌");
                   case 9:
                        return("玖");
                   case 0:
                        return("");
       }
}//end of numturn()


int main(int argc, char *argv[])
{
    char *num[20];int count,i;
    string s;
    while(cin>>*num) {
         s=*num;
         count=s.length();

         for (i=count;i>=1;i--) {
             switch(i) {
             case 10:
                  cout<<numturn(atoi(num[i]))<<"十" ;
                  break;
             case 9:
                  cout<<numturn(atoi(num[i]))<<"億" ;
                  break;
             case 8:
                  cout<<numturn(atoi(num[i]))<<"千" ;
                  break;
             case 7:
                  cout<<numturn(atoi(num[i]))<<"百" ;
                  break;
             case 6:
                  cout<<numturn(atoi(num[i]))<<"十" ;
                  break;
             case 5:
                  cout<<numturn(atoi(num[i]))<<"萬" ;
                  break;
             case 4:
                  cout<<numturn(atoi(num[i]))<<"千" ;
                  break;
             case 3:
                  cout<<numturn(atoi(num[i]))<<"百" ;
                  break;
             case 2:
                  cout<<numturn(atoi(num[i]))<<"十" ;
                  break;
             case 1:
                  cout<<numturn(atoi(num[i]));
                  break;
             }    
         }
    }
    return 0;
}
 

 

 
#449: Re:請求協助 我搞不懂


shadowevor (ShadowEvor)

學校 : 臺北市立建國高級中學
編號 : 2286
來源 : [59.117.213.125]
最後登入時間 :
2008-10-16 21:53:16
a008. 中文大寫數字 -- admin | From: [218.161.48.210] | 發表日期 : 2008-08-06 11:21

不好意思重複發表

 

可以刪除嗎?

 
#450: Re:請求協助 我搞不懂


POOHccc ()

學校 : 國立臺中技術學院
編號 : 1139
來源 : [220.135.97.253]
最後登入時間 :
2012-02-04 21:23:42
a008. 中文大寫數字 -- admin | From: [218.167.63.38] | 發表日期 : 2008-08-06 13:07

我是c++的初學者

字串的東西不太清楚

能夠麻煩幫我debug看看嗎?(我不知道問題在哪)

只要輸入就當掉(問題很大)

 

程式碼滿有點亂請見諒

 

#include <cstdlib>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
string numturn(int num)
{
       switch(num) {
                   case 1:
                        return("壹");
                   case 2:
                        return("貳");
                   case 3:
                        return("參");
                   case 4:
                        return("肆");
                   case 5:
                        return("伍");
                   case 6:
                        return("陸");
                   case 7:
                        return("柒");
                   case 8:
                        return("捌");
                   case 9:
                        return("玖");
                   case 0:
                        return("");
       }
}//end of numturn()


int main(int argc, char *argv[])
{
    char *num[20];int count,i;
    string s;
    while(cin>>*num) {
         s=*num;
         count=s.length();

         for (i=count;i>=1;i--) {
             switch(i) {
             case 10:
                  cout<<numturn(atoi(num[i]))<<"十" ;
                  break;
             case 9:
                  cout<<numturn(atoi(num[i]))<<"億" ;
                  break;
             case 8:
                  cout<<numturn(atoi(num[i]))<<"千" ;
                  break;
             case 7:
                  cout<<numturn(atoi(num[i]))<<"百" ;
                  break;
             case 6:
                  cout<<numturn(atoi(num[i]))<<"十" ;
                  break;
             case 5:
                  cout<<numturn(atoi(num[i]))<<"萬" ;
                  break;
             case 4:
                  cout<<numturn(atoi(num[i]))<<"千" ;
                  break;
             case 3:
                  cout<<numturn(atoi(num[i]))<<"百" ;
                  break;
             case 2:
                  cout<<numturn(atoi(num[i]))<<"十" ;
                  break;
             case 1:
                  cout<<numturn(atoi(num[i]));
                  break;
             }    
         }
    }
    return 0;
}
 

 


指標不是這樣用滴我是無辜的

建議你改用二維陣列試試看吧

 
ZeroJudge Forum