NYOJ 643 发短信

2014-11-24 12:32:37 · 作者: · 浏览: 0

发短信

时间限制:1000 ms | 内存限制:65535 KB 难度:3
描述
下图是手机常用的九键英文输入法界面,如果要输入字母'A',我们只 需要按一次数字键2,按键顺序记为2;如果要输入字母'B'的话,我们需要连续按两次数字键2,按键顺序记为22;同理:字母'C’需要连续按3次数字键2,按键顺序记为222。通过这种方法,我们用手机10多个键就能输入26个英文字母。 现在你的任务是统计一段英文用手机输入的按键顺序,同样,你也要能把按键顺序翻译成相应的英文内容。 为了使问题简化,我们假设内容只有大写英文字母和空格。 \
输入
有多组测试数据
每组测试数据占一行,有两种情况:
(1)短信内容(只含有若干个空格和大写字母,不超过1000个字符)
(2)短信按键顺序(只含有若干空格和数字,其中第一个肯定是数字,不超过1000个字符)
输出
对于每组测试数据:
如果是短信内容,输出每个字母的按键顺序,每个字母的按键顺序用空格隔开
如果是按键顺序,输出它代表的内容
样例输入
I LOVE YOU
HELLO WORLD
444 0 555 666 888 33 0 999 666 88
44 33 555 555 666 0 9 666 777 555 3
样例输出
444 0 555 666 888 33 0 999 666 88
44 33 555 555 666 0 9 666 777 555 3
I LOVE YOU
HELLO WORLD
直接模拟!
AC码:
#include
       
        
#include
        
          int main() { int i,a,b,j,count; char str[1005],ch; while(gets(str)) { if((str[0]>='A')&&(str[0]<='Z')||str[0]==' ') { for(i=0;str[i]!='\0';i++) { if(str[i]==' ') { printf("0 "); } else if(str[i]>='A'&&str[i]<='R') { a=(str[i]-'A')%3+1;// a为按键次数 b=(str[i]-'A')/3+2;// b为按的数字 for(j=1;j<=a;j++) printf("%d",b); printf(" "); } else if(str[i]=='S') printf("7777 "); else if(str[i]>='T'&&str[i]<='Y') { a=(str[i]-'T')%3+1; // a为按键次数 b=(str[i]-'T')/3+8; // b为按的数字 for(j=1;j<=a;j++) printf("%d",b); printf(" "); } else if(str[i]=='Z') printf("9999 "); } printf("\n"); } else { for(i=0;str[i]!='\0';i++) { if(str[i]==' ') continue; if(str[i]=='0') printf(" "); if(str[i]>='2'&&str[i]<='7') { count=0; a=str[i]-'0'; while(str[i]>='0'&&str[i]<='7') { count++; i++; } ch=(a-2)*3+'A'+(count-1); printf("%c",ch); } else if(str[i]>='8'&&str[i]<='9') { count=0; a=str[i]-'8'; while(str[i]>='8'&&str[i]<='9') { count++; i++; } ch=a*3+'T'+(count-1); printf("%c",ch); } } printf("\n"); } memset(str,0,sizeof(str)); } return 0; } 
        
       


<script type="text/java script">
<script type="text/java script">BAIDU_CLB_fillSlot("771048");
点击复制链接 与好友分享! 回本站首页
<script> function copyToClipBoard(){ var clipBoardContent=document.title + '\r\n' + document.location; clipBoardContent+='\r\n'; window.clipboardData.setData("Text",clipBoardContent); alert("恭喜您!复制成功"); }
分享到: 更多
<script type="text/java script" id="bdshare_js" data="type=tools&uid=12732"> <script type="text/java script" id="bdshell_js"> <script type="text/java script"> var bds_config = {'snsKey':{'tsina':'2386826374','tqq':'5e544a8fdea646c5a5f3967871346eb8'}}; document.getElementById("bdshell_js").src = "http://bdimg.share.baidu.com/static/js/shell_v2.js cdnversion=" + Math.ceil(new Date()/3600000)
您对本文章有什么意见或着疑问吗?请到 论坛讨论您的关注和建议是我们前行的参考和动力
上一篇: LeetCode::Trapping Rain Water
下一篇: Unix C++(boost) 线程同步和线程组
相关文章
<script type="text/java script">BAIDU_CLB_fillSlot("182716");
<script type="text/java script">BAIDU_CLB_fillSlot("517916");
图文推荐
<iframe src="http://www.2cto.com/uapi.php tid=298350&catid=339&title=TllPSiA2NDMgt6K2zNDF&forward=http://www.2cto.com/kf/201405/298350.html" width="100%" height="100%" id="comment_iframe" name="comment_iframe" frameborder="0" scrolling="no">
<script type="text/java script">BAIDU_CLB_fillSlot("771057");