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 |
小女初来乍到,本地没问题,但是WA~~受打击#include <iostream> #include <cstring> using namespace std; int main() { char morse[30][5]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--..","..--",".-.-","---.","----"}; char str[101],mor[401],cmp[5],*p; int num[100],id[30]={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}; int n,l,i,j,k,t; while(cin>>n) { getchar(); for(k=1;k<=n;k++) { cin.getline(str,100); l=strlen(str); mor[0]='\0'; for(i=0;i<l;i++) { if(str[i]>='A'&&str[i]<='Z') { t=str[i]-65; strcat(mor,morse[t]); num[l-1-i]=id[t]; } else if(str[i]=='_') { strcat(mor,morse[26]); num[l-1-i]=id[26]; } else if(str[i]==',') { strcat(mor,morse[27]); num[l-1-i]=id[27]; } else if(str[i]=='.') { strcat(mor,morse[28]); num[l-1-i]=id[28]; } else { strcat(mor,morse[29]); num[l-1-i]=id[29]; } } p=mor; cout<<k<<": "; for(i=0;i<l;i++) { strncpy(cmp,p,num[i]); cmp[num[i]]='\0'; p+=num[i]; for(j=0;j<30;j++) { if(strcmp(cmp,morse[j])==0) { if(j>=0&&j<=25) cout<<(char)(j+65); else if(j==26) cout<<"_"; else if(j==27) cout<<","; else if(j==28) cout<<"."; else cout<<"?"; break; } } } cout<<endl; } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator