acdream 1188 telephone number 模擬

鏈接:點擊打開鏈接

題意:讀電話號碼的方式,各種讀,主要是練習代碼能力

cpp:點擊打開鏈接

/*
* this code is made by ppaul
* Problem: 1188
* Verdict: Accepted
* Submission Date: 2014-08-29 21:56:10
* Time: 4MS
* Memory: 1680KB
*/
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <string>
#include <queue>
using namespace std;
#define maxn 40
int T,l;
string data,tp;
string hehe[10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
string haha[11]={"","","double","triple","quadruple","quintuple","sextuple","septuple","octuple","nonuple","decuple"};
void read(int &a) {
    int t;
    while (t = getchar(), t>'9'||t<'0');
    a = t - '0';
    while (t = getchar(), t>='0'&&t<='9') a = a * 10 + t - '0';
}
int main()
{
    int i;
    //freopen("data.in","r",stdin);
    scanf("%d",&T);
    int cas=0;
    while (T--)
    {
        printf("Case #%d: ",++cas);
        cin>>data;
        l=data.length();
        int tp;
        int cnt=0;
        while(l>0)
        {
            read(tp);
            l-=tp;
            int ll=0;
            int tttt;
            int oldt=-1;
            for(i=0;i<tp;i++,cnt++)
            {
                tttt=int(data[cnt]-'0');
                if(i==0)
                {
                    ll=1;
                }
                else if(tttt==oldt)
                {
                    ll++;
                }
                else {
                    if(ll==1)
                    {
                        cout<<hehe[oldt];
                    }
                    else if(ll<=10){
                        cout<<haha[ll]<<" "<<hehe[oldt];
                    }
                    else {
                        while(ll--)
                        {
                            cout<<hehe[tttt];
                            if(ll>1)
                            {
                                cout<<" ";
                            }
                        }
                    }
                    if(i<=tp-1)cout<<" ";
                    ll=1;
                }
                 
                if(i==tp-1)
                {
                    if(ll==1)
                    {
                        cout<<hehe[tttt];
                    }
                    else if(ll<=10){
                        cout<<haha[ll]<<" "<<hehe[tttt];
                    }
                    else {
                        while(ll--)
                        {
                            cout<<hehe[tttt];
                            if(ll>0)
                            {
                                cout<<" ";
                            }
                        }
                    }
                    if(l>0)cout<<" ";
                    else {
                        printf("\n");
                    }
                }
                oldt=tttt;
            }
        }
         
         
             
    }
    return 0;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章