40 条题解

  • 1
    @ 2016-11-01 19:09:46

    这才叫“比较傻的人学英语”
    #include<iostream>
    #include<cstdio>

    using namespace std;
    const int bl=1e9,ml=1e6,th=1e3;
    string s[110];
    int ns;
    void _init(){s[0]="zero";s[1]="one";s[2]="two";s[3]="three";s[4]="four";s[5]="five";
    s[6]="six";s[7]="seven";s[8]="eight";s[9]="nine";s[10]="ten";s[11]="eleven";s[12]="twelve";
    s[13]="thirteen";s[14]="fourteen";s[15]="fifteen";s[16]="sixteen";s[17]="seventeen";
    s[18]="eighteen";s[19]="nineteen";s[20]="twenty";s[21]="twenty-one";s[22]="twenty-two";
    s[23]="twenty-three";s[24]="twenty-four";s[25]="twenty-five";s[26]="twenty-six";
    s[27]="twenty-seven";s[28]="twenty-eight";s[29]="twenty-nine";s[30]="thirty";
    s[31]="thirty-one";s[32]="thirty-two";s[33]="thirty-three";s[34]="thirty-four";
    s[35]="thirty-five";s[36]="thirty-six";s[37]="thirty-seven";s[38]="thirty-eight";
    s[39]="thirty-nine";s[40]="forty";s[41]="forty-one";s[42]="forty-two";
    s[43]="forty-three";s[44]="forty-four";s[45]="forty-five";s[46]="forty-six";
    s[47]="forty-seven";s[48]="forty-eight";s[49]="forty-nine";s[50]="fifty";
    s[51]="fifty-one";s[52]="fifty-two";s[53]="fifty-three";s[54]="fifty-four";
    s[55]="fifty-five";s[56]="fifty-six";s[57]="fifty-seven";s[58]="fifty-eight";
    s[59]="fifty-nine";s[60]="sixty";s[61]="sixty-one";s[62]="sixty-two";
    s[63]="sixty-three";s[64]="sixty-four";s[65]="sixty-five";s[66]="sixty-six";
    s[67]="sixty-seven";s[68]="sixty-eight";s[69]="sixty-nine";s[70]="seventy";
    s[71]="seventy-one";s[72]="seventy-two";s[73]="seventy-three";s[74]="seventy-four";
    s[75]="seventy-five";s[76]="seventy-six";s[77]="seventy-seven";s[78]="seventy-eight";
    s[79]="seventy-nine";s[80]="eighty";s[81]="eighty-one";s[82]="eighty-two";
    s[83]="eighty-three";s[84]="eighty-four";s[85]="eighty-five";s[86]="eighty-six";
    s[87]="eighty-seven";s[88]="eighty-eight";s[89]="eighty-nine";s[90]="ninety";
    s[91]="ninety-one";s[92]="ninety-two";s[93]="ninety-three";s[94]="ninety-four";
    s[95]="ninety-five";s[96]="ninety-six";s[97]="ninety-seven";s[98]="ninety-eight";
    s[99]="ninety-nine";s[100]="one hundred";}
    void billion(int n)
    {
    if(!n)return;
    bool fg=0;
    if(n/100)cout<<s[n/100]<<" hundred",fg=1;
    n%=100;if(n){if(fg)cout<<" and ";cout<<s[n];}
    cout<<" billion";
    }
    void million(int n)
    {
    if(!n)return;
    if(n&&ns>bl)cout<<" ";
    if(n&&ns>bl&&n<100)cout<<"and ";
    bool fg=0;
    if(n/100)cout<<s[n/100]<<" hundred",fg=1;
    n%=100;if(n){if(fg)cout<<" and ";cout<<s[n];}
    cout<<" million";
    }
    void thousand(int n)
    {
    if(!n)return;
    if(n&&ns>ml)cout<<" ";
    if(n&&ns>ml&&n<100)cout<<"and ";
    bool fg=0;
    if(n/100)cout<<s[n/100]<<" hundred",fg=1;
    n%=100;if(n){if(fg)cout<<" and ";cout<<s[n];}
    cout<<" thousand";
    }
    void _1(int n)
    {
    if(n&&ns>th)cout<<" ";
    if(n&&ns>th&&n<100)cout<<"and ";
    bool fg=0;
    if(n/100)cout<<s[n/100]<<" hundred",fg=1;
    n%=100;if(n){if(fg)cout<<" and ";cout<<s[n];}
    }
    int main()
    {
    _init();
    int n;cin>>n;ns=n;
    if(!n)cout<<s[0];
    else
    {
    billion(n/bl);n%=bl;
    million(n/ml);n%=ml;
    thousand(n/th);n%=th;
    _1(n);

    }
    }

  • 0
    @ 2017-08-14 20:51:46

    做这题我仿佛变成了傻子

  • 0
    @ 2016-09-03 12:06:58

    改了许多细节,好不容易AC了。
    shadowshore貌似自动把输出中间的空格给忽略了。
    c++
    #include<iostream>
    using namespace std;
    bool flag;
    void print(string s){
    while(s.length()!=3)s=" "+s;
    char c=s[0];
    //cout<<c<<endl;
    switch(c){
    case'1':cout<<"one";break;
    case'2':cout<<"two";break;
    case'3':cout<<"three";break;
    case'4':cout<<"four";break;
    case'5':cout<<"five";break;
    case'6':cout<<"six";break;
    case'7':cout<<"seven";break;
    case'8':cout<<"eight";break;
    case'9':cout<<"nine";break;
    }
    if(c>'0')cout<<" hundred ";
    if((s[1]>'0'||s[2]>'0')&&c>'0'||flag&&c=='0')cout<<"and ";
    flag=0;
    c=s[1];
    switch(c){
    case'2':cout<<"twenty";break;
    case'3':cout<<"thirty";break;
    case'4':cout<<"forty";break;
    case'5':cout<<"fifty";break;
    case'6':cout<<"sixty";break;
    case'7':cout<<"seventy";break;
    case'8':cout<<"eighty";break;
    case'9':cout<<"ninety";break;
    case'1':
    switch(s[2]){
    case'0':cout<<"ten";break;
    case'1':cout<<"eleven";break;
    case'2':cout<<"twelve";break;
    case'3':cout<<"thirteen";break;
    case'4':cout<<"fourteen";break;
    case'5':cout<<"fifteen";break;
    case'6':cout<<"sixteen";break;
    case'7':cout<<"seventeen";break;
    case'8':cout<<"eighteen";break;
    case'9':cout<<"nineteen";break;
    }
    }
    if(c>'1'&&s[2]!='0')cout<<'-';else
    if(c=='1')
    return;
    c=s[2];
    switch(c){
    case'1':cout<<"one";break;
    case'2':cout<<"two";break;
    case'3':cout<<"three";break;
    case'4':cout<<"four";break;
    case'5':cout<<"five";break;
    case'6':cout<<"six";break;
    case'7':cout<<"seven";break;
    case'8':cout<<"eight";break;
    case'9':cout<<"nine";break;
    }
    }
    int main(){
    string s,t="";
    cin>>s;
    if(s=="0"){
    cout<<"zero"<<endl;
    return 0;
    }
    string a[5];
    int n=s.length()+2;
    n/=3;
    int p=n;
    for(int i=s.length()-1;i>=0;i--){
    t=s[i]+t;
    //cout<<t<<endl;
    if(t.length()==3){
    a[p--]=t;
    //cout<<p+1<<' '<<t<<endl;
    t="";
    }
    }
    if(t.length()>0)
    a[1]=t;
    for(int i=1;i<=n;i++){
    //cout<<a[i]<<endl;
    if(a[i]=="000"){
    continue;
    }
    print(a[i]);
    //if(a[i].length()==3)
    flag=1;
    //cout<<n<<endl;
    switch(n){
    case 1:
    cout<<endl;
    return 0;
    case 2:
    if(i==1)
    cout<<" thousand ";else{
    cout<<endl;
    return 0;
    }
    break;
    case 3:
    switch(i){
    case 1:
    cout<<" million ";break;
    case 2:
    cout<<" thousand ";break;
    case 3:
    cout<<endl;
    return 0;
    }break;
    case 4:
    switch(i){
    case 1:
    cout<<" billion ";break;
    case 2:
    cout<<" million ";break;
    case 3:
    cout<<" thousand ";break;
    case 4:
    cout<<endl;
    return 0;
    }
    }
    }
    }

  • 0
    @ 2016-01-30 11:23:07

    受不了vijos的评测机

  • 0
    @ 2016-01-01 11:19:53

    AC 100题留念

  • 0
    @ 2015-08-14 11:07:54

    保存0.0
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    using namespace std;
    bool bk;
    void ge(int x)
    {
    if(x==1)cout<<"one";
    else if(x==2)cout<<"two";
    else if(x==3)cout<<"three";
    else if(x==4)cout<<"four";
    else if(x==5)cout<<"five";
    else if(x==6)cout<<"six";
    else if(x==7)cout<<"seven";
    else if(x==8)cout<<"eight";
    else if(x==9)cout<<"nine";
    else cout<<"zero";
    }
    void shi(int x)
    {
    if(x==1)cout<<"ten";
    else if(x==2)cout<<"twenty";
    else if(x==3)cout<<"thirty";
    else if(x==4)cout<<"fourty";
    else if(x==5)cout<<"fifty";
    else if(x==6)cout<<"sixty";
    else if(x==7)cout<<"seventy";
    else if(x==8)cout<<"eighty";
    else cout<<"ninety";
    }
    void bt(int x)
    {
    if(x==11)cout<<"eleven";
    else if(x==12)cout<<"twelve";
    else if(x==13)cout<<"thirteen";
    else if(x==14)cout<<"fourteen";
    else if(x==15)cout<<"fifteen";
    else if(x==16)cout<<"sixteen";
    else if(x==17)cout<<"seventeen";
    else if(x==18)cout<<"eighteen";
    else cout<<"nineteen";
    }
    /*
    void bai(int x)
    {
    if(x==1)cout<<"one hundred";
    else if(x==2)cout<<"two hundred";
    else if(x==3)cout<<"three hundred";
    else if(x==4)cout<<"four hundred";
    else if(x==5)cout<<"five hundred";
    else if(x==6)cout<<"six hundred";
    else if(x==7)cout<<"seven hundred";
    else if(x==8)cout<<"eight hundred";
    else cout<<"nine hundred";
    }
    void qian(int x)
    {
    if(x==1)cout<<"one thousand";
    else if(x==2)cout<<"two thousand";
    else if(x==3)cout<<"three thousand";
    else if(x==4)cout<<"four thousand";
    else if(x==5)cout<<"five thousand";
    else if(x==6)cout<<"six thousand";
    else if(x==7)cout<<"seven thousand";
    else if(x==8)cout<<"eight thousand";
    else cout<<"nine thousand";
    }
    */
    int main()
    {
    while(1)
    {
    int len,a[11],t;char ss[11];bool kg=false;
    scanf("%s",ss+1);len=strlen(ss+1);t=len+1;
    memset(a,-1,sizeof(a));
    for(int i=1;i<=len;i++)
    {
    a[--t]=ss[i]-'0';
    }
    if(a[10]!=-1&&a[10]!=0)
    {
    if(kg==true)printf(" ");
    ge(a[10]);
    cout<<" billion";
    kg=true;
    }

    kg=false;

    if(a[9]!=-1&&a[9]!=0)
    {
    if(kg==true)cout<<" ";
    ge(a[9]);
    cout<<" hundred";
    kg=true;
    }
    if(a[8]!=-1&&a[8]!=0)
    {
    if(kg==true)cout<<" ";
    kg=true;
    if(a[9]!=-1&&a[9]!=0)cout<<"and ";
    if((a[8]*10+a[7])>10&&(a[8]*10+a[7])<20)bt(a[8]*10+a[7]);
    else if(a[7]==0)
    {
    shi(a[8]);
    }
    else
    {
    shi(a[8]);
    cout<<"-";
    ge(a[7]);
    }
    }
    if(a[8]==-1&&a[9]==-1&&a[7]!=-1)
    {
    ge(a[7]);
    if(kg==true)cout<<" ";
    kg=true;
    }
    else if(a[9]>0||a[8]>0&&a[7]>0)
    {
    if(kg==true)cout<<" ";
    kg=true;
    cout<<"and ";
    ge(a[1]);
    }
    if(a[7]>0||a[8]>0||a[9]>0)cout<<" thousand";
    if(a[6]!=-1&&a[6]!=0)
    {
    if(kg==true)cout<<" ";
    ge(a[6]);
    cout<<" hundred";
    kg=true;
    }
    if(a[5]!=-1&&a[5]!=0)
    {
    if(kg==true)cout<<" ";
    kg=true;
    if(a[6]!=-1&&a[6]!=0)cout<<"and ";
    if((a[5]*10+a[4])>10&&(a[5]*10+a[4])<20)bt(a[5]*10+a[4]);
    else if(a[4]==0)
    {
    shi(a[5]);
    }
    else
    {
    shi(a[5]);
    cout<<"-";
    ge(a[4]);
    }
    }
    if(a[5]==-1&&a[6]==-1&&a[4]!=-1)
    {
    ge(a[4]);
    if(kg==true)cout<<" ";
    kg=true;
    }
    else if(a[6]>0||a[5]>0&&a[4]>0)
    {
    if(kg==true)cout<<" ";
    kg=true;
    cout<<"and ";
    ge(a[1]);
    }
    if(a[4]>0||a[5]>0||a[6]>0)cout<<" thousand";
    if(a[3]!=-1&&a[3]!=0)
    {
    if(kg==true)cout<<" ";
    ge(a[3]);
    cout<<" hundred";
    kg=true;
    }
    if(a[2]!=-1&&a[2]!=0)
    {
    if(kg==true)cout<<" ";
    kg=true;
    if(a[3]!=-1&&a[3]!=0)cout<<"and ";
    if((a[2]*10+a[1])>10&&(a[2]*10+a[1])<20)bt(a[2]*10+a[1]);
    else if(a[1]==0)
    {
    shi(a[2]);
    }
    else
    {
    shi(a[2]);
    cout<<"-";
    ge(a[1]);
    }
    }
    if(a[2]==-1&&a[3]==-1&&a[1]!=-1)
    {
    ge(a[1]);
    }
    else if(a[3]>0||a[2]>0&&a[1]>0)
    {
    if(kg==true)cout<<" ";
    kg=true;
    cout<<"and ";
    ge(a[1]);
    }
    printf("\n"); }
    return 0;
    }

  • 0
    @ 2014-08-07 18:44:34

    这题有人打表吗??

  • 0
    @ 2014-05-04 18:53:00

    program lx;
    var t,m,n,i,j,k,l,o:longint;
    s:string;
    begin
    l:=0;m:=1;
    readln(s);l:=length(s);
    for i:=(l div 3) downto 0 do
    begin t:=0;
    for j:=m to l-i*3 do
    begin o:=1;
    if s[j]<>'0' then o:=1;
    if l-i*3-j=2 then
    begin case s[j] of
    '1':write('one ');
    '2':write('two ');
    '3':write('three ');
    '4':write('four ');
    '5':write('five ');
    '6':write('six ');
    '7':write('seven ');
    '8':write('eight ');
    '9':write('nine ');
    end;
    if s[j]<>'0' then write('hundred ');
    if (s[j+1]<>'0')or(s[j+2]<>'0') then write('and ');
    end;
    if l-i*3-j=1 then
    begin
    case s[j] of
    '2':write('twenty');
    '3':write('thirty');
    '4':write('forty');
    '5':write('fifty');
    '6':write('sixty');
    '7':write('seventy');
    '8':write('eighty');
    '9':write('nine','ty');
    end;
    if (s[j+1]<>'0')and(s[j]<>'1')and(s[j]<>'0') then write('-');
    end;
    if l-i*3-j=0 then
    begin
    if s[j-1]='1' then
    case s[j] of
    '0':write('ten');
    '1':write('eleven');
    '2':write('twelve');
    '3':write('thirteen');
    '4':write('fourteen');
    '5':write('fifteen');
    '6':write('sixteen');
    '7':write('seventeen');
    '8':write('eighteen');
    '9':write('nine','teen');
    end;
    if s[j-1]<>'1' then
    case s[j] of
    '1':write('one');
    '2':write('two');
    '3':write('three');
    '4':write('four');
    '5':write('five');
    '6':write('six');
    '7':write('seven');
    '8':write('eight');
    '9':write('nine');
    end;
    end;
    end;
    m:=l-i*3+1; if (m<L+1)and(o=1) then write(' ');
    if (o=1)and(j=m-1) then case i of
    1:write('thousand ');
    2:write('million ');
    3:write('billion ');

    end;
    end;
    end.

  • 0
    @ 2013-08-26 19:56:45

    AC50纪念

  • 0
    @ 2013-08-18 09:59:41

    AC150

  • 0
    @ 2009-11-05 13:23:47

    英国人真啰嗦

    中文一笔带过,英文要三行

  • 0
    @ 2009-10-30 20:06:30

    我恨英语……

  • 0
    @ 2009-08-07 11:42:07

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    1001要输出one thousand and one...

    我一直以为是one thousand one..

    英语不过关 囧。

    比较简单,三位三位处理。50行AC。

  • 0
    @ 2009-05-28 01:53:41

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ├ 测试数据 06:答案正确... 0ms

    ├ 测试数据 07:答案正确... 0ms

    ├ 测试数据 08:答案正确... 0ms

    ├ 测试数据 09:答案正确... 0ms

    ├ 测试数据 10:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    3个小时,提交8次,还是题吗?

    学英语的人比较傻呀!

    下面附我猥琐的程序:(为学GCC的人带来福音)

    #include "stdio.h"

    #include "string.h"

    int main()

    {

    int t,m,n,i,j,k,l,o;

    char s[20];

    gets(s);

    l=strlen(s);

    m=0;

    for(i=l/3;i>=0;i--)

    {

    t=0;

    for(j=0;j

  • 0
    @ 2009-02-26 18:28:49

    思路。。。。?题意是什么?

  • 0
    @ 2009-01-31 21:20:43

    这道题被我拉下两个点。。。

    提交了10次终于AC了 寒-_-||

    and 和 空格 特别要注意

  • 0
    @ 2009-01-31 19:26:58

    第108个

    硬输出

  • 0
    @ 2009-01-22 20:06:21

    Flag   Accepted

    题号   P1356

    类型(?)   其它

    通过   104人

    提交   310次

    通过率   34%

    难度   1

  • 0
    @ 2009-01-02 19:23:28

    3位3位分开来再处理,E文麻烦了点。

    PS:楼下那位,你牛,这么长都打出来了。。。

  • 0
    @ 2008-12-21 14:59:03

    #include

    #include

    using namespace std;

    #define era_se era##se

    string&cvt_st(string&s,int n,bool f) {

    int h=n/10%10,l=n%10,a;

    if(a=n/1000000000) cvt_st(s,a,false)+=" billion ",n%=1000000000;

    if(a=n/1000000%1000) cvt_st(s,a,true)+=" million ",n%=1000000;

    if(a=n/1000%1000) cvt_st(s,a,true)+=" thousand ",n%=1000;

    if(a=n/100%10) cvt_st(s,a,false)+=" hundred ",n%=100;

    if(f&&(h||l)&&s.length()) s+="and ";

    switch(h) {

    case 9: (s+="nine")+="ty";break; //对不起,您提交的代码中包含非法字符串 NET

    case 8: s+="eighty";break;

    case 7: s+="seventy";break;

    case 6: s+="sixty";break;

    case 5: s+="fifty";break;

    case 4: s+="forty";break;

    case 3: s+="thirty";break;

    case 2: s+="twenty";break;

    case 1: switch(l) {

    case 9: (s+="nine")+="teen";break; //对不起,您提交的代码中包含非法字符串 NET

    case 8: s+="eighteen";break;

    case 7: s+="seventeen";break;

    case 6: s+="sixteen";break;

    case 5: s+="fifteen";break;

    case 4: s+="fourteen";break;

    case 3: s+="thirteen";break;

    case 2: s+="twelve";break;

    case 1: s+="eleven";break;

    case 0: s+="ten";

    } break;

    case 0: switch(l) {

    case 9: s+="nine";break;

    case 8: s+="eight";break;

    case 7: s+="seven";break;

    case 6: s+="six";break;

    case 5: s+="five";break;

    case 4: s+="four";break;

    case 3: s+="three";break;

    case 2: s+="two";break;

    case 1: s+="one";

    }

    } if(h>=2&&l) cvt_st(s+='-',l,false);

    for(a=s.length()-1;s[a]==' ';s.era_se(a--,1)); //对不起,您提交的代码中包含非法字符串 Erase

    return s;

    }

    int main() {

    int n;

    string s;

    cin>>n;

    cout

信息

ID
1356
难度
5
分类
模拟 点击显示
标签
(无)
递交数
434
已通过
144
通过率
33%
被复制
4
上传者