• ACdream 1188 Read Phone Number (字符串大模拟)


    Read Phone Number
    Time Limit:1000MS     Memory Limit:64000KB     64bit IO Format:%lld & %llu

    Description

    Do you know how to read the phone numbers in English? Now let me tell you.

    For example, In China, the phone numbers are 11 digits, like: 15012233444. Someone divides the numbers into 3-4-4 format, i.e. 150 1223 3444. While someone divides the numbers into 3-3-5 format, i.e. 150 122 33444. Different formats lead to different ways to read these numbers:

    150 1223 3444 reads one five zero one double two three three triple four.

    150 122 33444 reads one five zero one double two double three triple four.

    Here comes the problem:

    Given a list of phone numbers and the dividing formats, output the right ways to read these numbers.

    Rules:

    Single numbers just read them separately.

    2 successive numbers use double.

    3 successive numbers use triple.

    4 successive numbers use quadruple.

    5 successive numbers use quintuple.

    6 successive numbers use sextuple.

    7 successive numbers use septuple.

    8 successive numbers use octuple.

    9 successive numbers use nonuple.

    10 successive numbers use decuple.

    More than 10 successive numbers read them all separately.

    Input

    The first line of the input gives the number of test cases, T(1 ≤ T ≤ 100).

    T test cases follow. Each line contains a phone number N(1 ≤ length of N ≤ 100) and the dividing format F, one or more positive integers separated by dashes (-), without leading zeros and whose sum always equals the number of digits in the phone number.

    Output

    For each test case, output one line containing "Case #x: y", where  x is the case number (starting from 1) and  y is the reading sentence in English whose words are separated by a space.

    Sample Input

    3
    15012233444 3-4-4
    15012233444 3-3-5
    12223 2-3

    Sample Output

    Case #1: one five zero one double two three three triple four
    Case #2: one five zero one double two double three triple four
    Case #3: one two double two three
    题意样例输入输出就能看懂,注意10个以上数字要单独输出,是个字符串大模拟。
    #include <iostream>
    #include <cstdio>
    #include <string.h>
    using namespace std;
    char data[200][200]={"double","triple","quadruple","quintuple","sextuple",
    "septuple","octuple","nonuple","decuple"};
    char aa[200][200]={"zero","one","two","three","four","five","six","seven","eight","nine","decuple"};
    int main()
    {
        int t,cas=1;
        scanf("%d",&t);
        while(t--)
        {
            char c[1005],d[1005];
            scanf("%s",c);
            scanf("%s",d);
            int len1=strlen(c);
            int len2=strlen(d);
            int a[1005];
            for(int i=0;i<len1;i++)
            a[i]=c[i]-'0';
            int fen[1005],cnt=0,tmp=0;
            printf("Case #%d:",cas++);
            for(int i=0;i<len2;i++)
            {
                if(d[i]!='-')
                {
                    tmp=tmp*10;
                    tmp+=d[i]-'0';
                }
                else
                {
                    fen[cnt++]=tmp;
                    tmp=0;
                }
            }
            if(tmp) fen[cnt++]=tmp;
            //for(int i=0;i<cnt;i++)
            //cout<<fen[i]<<endl;
            int b=1;
            int sum=0;
            for(int i=0;i<cnt;i++)
            {
                b=1;
                for(int j=sum;j<sum+fen[i];j++)
                {
                    if(j+1<sum+fen[i])
                    {
                        if(a[j]==a[j+1])
                            b++;
                        else
                        {
                            if(b==1)
                            {
                                cout<<" "<<aa[a[j]];
                            }
                            else if(b>1&&b<=10)
                            {
                                cout<<" "<<data[b-2]<<" "<<aa[a[j]];
                                b=1;
                            }
                            else
                            {
                                for(int k=0;k<b;k++)
                                cout<<" "<<aa[a[j]];
                                b=1;
                            }
                        }
                    }
                    else //最后一个字符了
                    {
                        if(b==1)
                        {
                            cout<<" "<<aa[a[j]];
                        }
                        else if(b>1&&b<=10)
                        {
                            cout<<" "<<data[b-2]<<" "<<aa[a[j]];
                            b=1;
                        }
                        else
                        {
                            for(int k=0;k<b;k++)
                            cout<<" "<<aa[a[j]];
                            b=1;
                        }
                    }
                }
                sum+=fen[i];
            }
            cout<<endl;
        }
        return 0;
    }
     
  • 相关阅读:
    MinIO监控指南
    使用kuboard部署某一个应用的pod分布于不同的主机上
    使用 Shell 命令 分析服务器日志
    K8S容器HeadlessService间动态IP通信
    科技动态
    Minio纠删码快速入门
    关于使用kuboard安装其自带的监控应用的注意事项
    MinIO存储桶通知指南
    网络稳定性测试
    使用filebeat收集k8s上pod里的容器日志配置文件模板
  • 原文地址:https://www.cnblogs.com/Ritchie/p/5712006.html
Copyright © 2020-2023  润新知