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 <iostream> using namespace std; char Alphabet[][5]={".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."}; char Mark[][5]={"..--","---.",".-.-","----"}; int main(int argc, char* argv[]) { int n,i,j,k; char szMessage[101]={'\0'}; char szCode[500]={'\0'}; int nNumbers[101]; int nNumberCount = 0; char *pChar; char szTemp[5]={'\0'}; cin>>n; for (i = 0;i<n;i++) { memset(szMessage,0,sizeof(szMessage)); cin>>szMessage; cout<<i+1<<": "; memset(szCode,0,sizeof(szCode)); pChar = szCode; nNumberCount = 0; int nCount=strlen(szMessage); for (j=0;j<nCount;j++) { nNumberCount ++; if (szMessage[j]>='A' && szMessage[j]<='Z') { nNumbers[j] = strlen(Alphabet[szMessage[j] - 'A']); strcat(szCode,Alphabet[szMessage[j]-'A']); } else { int nFlag; switch(szMessage[j]) { default:break; case 95:nFlag = 0;break; case 46:nFlag = 1;break; case 44:nFlag = 2;break; case 63:nFlag = 3;break; } nNumbers[j] = strlen(Mark[nFlag]); strcat(szCode,Mark[nFlag]); } } for (j=0;j<nNumberCount;j++) { memset(szTemp,0,sizeof(szTemp)); memcpy(szTemp,pChar,sizeof(char)*nNumbers[nNumberCount - j -1]); for (k=0;k<26;k++) if (strcmp(Alphabet[k],szTemp) == 0) cout<<char(k+'A'); for (k=0;k<4;k++) if (strcmp(Mark[k],szTemp) == 0) { switch(k) { default:break; case 0:cout<<"_";break; case 1:cout<<".";break; case 2:cout<<",";break; case 3:cout<<"?";break; } } pChar = pChar +nNumbers[nNumberCount - j -1]; } 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