Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
很烦,贴代码#include "cstdio" #include "cstring" char hash[32][6]={{".-"},{"-..."},{"-.-."},{"-.."},{"."},{"..-."},{"--."},{"...."},{".."},{".---"},{"-.-"},{".-.."},{"--"},{"-."},{"---"},{".--."},{"--.-"},{".-."},{"..."},{"-"},{"..-"},{"...-"},{".--"},{"-..-"},{"-.--"},{"--.."},{"..--"},{".-.-"},{"---."},{"----"}}; int len[32]={2,4,4,3,1,4,3,4,2,4,3,4,2,2,3,4,4,3,3,1,3,4,3,4,4,4,4,4,4,4}; char str[1000]; int lensq[120],sqi; void scopy(int x) { int i=0,lens=strlen(str); while(hash[x][i]) { str[lens]=hash[x][i]; i++; lens++; } str[lens]=0; lensq[sqi++]=i; } void print(int l,int start) { int j; char buff[6]; for(j=0;j<l;j++) buff[j]=str[start+j]; buff[j]=0; for(int i=0;i<30;i++) { if(len[i]==l&&!strcmp(buff,hash[i])) { if(i<26) putchar('A'+i); else if(i==26) putchar('_'); else if(i==27) putchar(','); else if(i==28) putchar('.'); else putchar('?'); break; } } } int main() { int t,i,k; char ch; scanf("%d",&t); getchar(); for(i=1;i<=t;i++) { str[0]=0; sqi=0; while((ch=getchar())!='\n') { if(ch>='A'&&ch<='Z') scopy(ch-'A'); else if(ch=='_') scopy(26); else if(ch==',') scopy(27); else if(ch=='.') scopy(28); else if(ch=='?') scopy(29); } // puts(str); printf("%d: ",i); k=0; for(int j=sqi-1;j>=0;j--) { print(lensq[j],k); k+=lensq[j]; } puts(""); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator