房天下 > 房天下问答 > 业主生活 > 其他
  • C++编写关于手机键盘程序

    编写一个手机键盘程序 例如:输如abc需要5秒钟,输完a需等待1秒在输入b输入完在等待1秒,加上按键的时间共5秒分组:abc和(1)对应 def和(2)对应 ghi对应(3) 按手机键盘上数字分组在同一组内的字符需等待1秒中要求:算出来输入任意一个字符串需要的时间是多少

    提问者:魔法天使团

    发布于2011-01-28

共1个回答
  • chen0596cong 丨Lv 4
    #include "iostream"using namespace std;int letter[28]={1,3,5,1,3,5,1,3,5,1,3,5,1,3,5,1,3,5,7,1,3,5,1,3,5,7,1,0}; // a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,zint main(){char *start,*next;char str[100];int sum = 0;while(cin>>str){ start = str; next = str+1; while(*start != '\0') { while((*next - *start == 1&&letter[*next - 'a']-letter[*start - 'a']==2)||(*next - *start == 2&&letter[*next - 'a']-letter[*start - 'a']==4)||(*next - *start == 3&&letter[*next - 'a']-letter[*start - 'a']==6)) //ab abc bc ac wz { start = next; next++; } /***********************************/ /**/if((*next - *start == -1&&letter[*next - 'a']-letter[*start - 'a']==-2)||(*next - *start == -2&&letter[*next - 'a']-letter[*start - 'a']==-4)||(*next - *start == -3&&letter[*next - 'a']-letter[*start - 'a']==-6)) /**/{ /**/ sum++;//按下c之后,下一个字母a,要不要等1秒,不要的话请注释这行 /**/} /**/else /**/ sum++;//按下c之后,下一个字母d,要不要等1秒,不要的话请注释这行 /***********************************/ sum+=letter[*start - 'a']; start = next; next++; } /***********************************/ /**/sum = sum - 1;//以上两行sum++都注释了的话,请注释这行 /***********************************/ cout<<sum<<endl; sum = 0;}return 1;}
    +1 2011-01-28 举报
热门人气推荐
免责声明:问答内容均来源于互联网用户,房天下对其内容不负责任,如有版权或其他问题可以联系房天下进行删除。