入门模拟——(字符串处理)B1002.写出这个数 + A1005. Spell It Right

入门模拟——(字符串处理)B1002.写出这个数 + A1005. Spell It Right_第1张图片

 

 

#include 
#include
using namespace std;
const int MAX_LEN = 105;
//const int MAX_D = 31;
int main(){
    char temp[MAX_LEN];
    for(int i=0;ii){
        temp[i] = 'c';
    }
    cin>>temp;
    int sum = 0;
    for(int i =0;ii){
        if((temp[i]-'0')>=0 && (temp[i]-'0')<=9){
            sum += (temp[i]-'0');
        }
    }
    int result[1000];
    for(int i=0;i<1000;++i){
        result[i] = 9;
    }
    int digit = 0;
    while(sum != 0){
        int t = sum % 10;
        sum = sum/10;
        result[digit] = t;
        digit++;
    }
    for(int i=digit-1;i>=0;--i){
        if(i == digit-1){
            if(result[i] == 1){
                cout<<"one";
            }
            if(result[i] == 2){
                cout<<"two";
            }
            if(result[i] == 3){
                cout<<"three";
            }
            if(result[i] == 4){
                cout<<"four";
            }
            if(result[i] == 5){
                cout<<"five";
            }
            if(result[i] == 6){
                cout<<"six";
            }
            if(result[i] == 7){
                cout<<"seven";
            }
            if(result[i] == 8){
                cout<<"eight";
            }
            if(result[i] == 9){
                cout<<"nine";
            }
        }
        else{
            if(result[i] == 0){
                cout<<" "<<"zero";
            }
            if(result[i] == 1){
                cout<<" "<<"one";
            }
            if(result[i] == 2){
                cout<<" "<<"two";
            }
            if(result[i] == 3){
                cout<<" "<<"three";
            }
            if(result[i] == 4){
                cout<<" "<<"four";
            }
            if(result[i] == 5){
                cout<<" "<<"five";
            }
            if(result[i] == 6){
                cout<<" "<<"six";
            }
            if(result[i] == 7){
                cout<<" "<<"seven";
            }
            if(result[i] == 8){
                cout<<" "<<"eight";
            }
            if(result[i] == 9){
                cout<<" "<<"nine";
            }
            
        }
        
    }
    system("pause");
    return 0;
} 

 

 

入门模拟——(字符串处理)B1002.写出这个数 + A1005. Spell It Right_第2张图片

 

 

#include 
#include
using namespace std;
const int MAX_LEN = 105;
//const int MAX_D = 31;
int main(){
    char temp[MAX_LEN];
    for(int i=0;ii){
        temp[i] = 'c';
    }
    cin>>temp;
    int sum = 0;
    for(int i =0;ii){
        if((temp[i]-'0')>=0 && (temp[i]-'0')<=9){
            sum += (temp[i]-'0');
        }
    }
    int result[1000];
    for(int i=0;i<1000;++i){
        result[i] = 9;
    }
    int digit = 0;
    while(sum != 0){
        int t = sum % 10;
        sum = sum/10;
        result[digit] = t;
        digit++;
    }
    for(int i=digit-1;i>=0;--i){
        if(i == digit-1){
            if(result[i] == 1){
                cout<<"yi";
            }
            if(result[i] == 2){
                cout<<"er";
            }
            if(result[i] == 3){
                cout<<"san";
            }
            if(result[i] == 4){
                cout<<"si";
            }
            if(result[i] == 5){
                cout<<"wu";
            }
            if(result[i] == 6){
                cout<<"liu";
            }
            if(result[i] == 7){
                cout<<"qi";
            }
            if(result[i] == 8){
                cout<<"ba";
            }
            if(result[i] == 9){
                cout<<"jiu";
            }
        }
        else{
            if(result[i] == 0){
                cout<<" "<<"ling";
            }
            if(result[i] == 1){
                cout<<" "<<"yi";
            }
            if(result[i] == 2){
                cout<<" "<<"er";
            }
            if(result[i] == 3){
                cout<<" "<<"san";
            }
            if(result[i] == 4){
                cout<<" "<<"si";
            }
            if(result[i] == 5){
                cout<<" "<<"wu";
            }
            if(result[i] == 6){
                cout<<" "<<"liu";
            }
            if(result[i] == 7){
                cout<<" "<<"qi";
            }
            if(result[i] == 8){
                cout<<" "<<"ba";
            }
            if(result[i] == 9){
                cout<<" "<<"jiu";
            }
            
        }
        
    }
    system("pause");
    return 0;
} 

你可能感兴趣的:(入门模拟——(字符串处理)B1002.写出这个数 + A1005. Spell It Right)