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 |
简单粗暴的蠢解法,0MS#include <iostream> #include <string.h> using namespace std; const int code_num = 30; const int char_len[code_num] = {2,4,3,4,4,2,4,3,4,4,4,4,3,3,3,4,1,4,3,4,4,2,1,3,2,3,4,4,4,4}; const int cum_char_len[code_num] = {2,6,9,13,17,19,23,26,30,34,38,42,45,48,51,55,56,60,63,67,71,73,74,77,79,82,86,90,94,98}; const string chars = "AHOVBIPWCJQXDKRYELSZFMTGNU_.,?"; const string Morse = ".-....---...--......--..---.-..-----.--..--..-.-.-.-.--..-.....--....-.-----.-...-..-----..-.-----"; int decode(string M_str, int start_p, int diff){ string temp_str; for(int k=0;k<code_num;k++){ if(char_len[k] == diff){ if(k==0) temp_str = string(Morse.substr(0,diff)); else temp_str = string(Morse.substr(cum_char_len[k-1],diff)); if(temp_str == string(M_str.substr(start_p,diff))) return k; } } } string convt(string in_str){ string Morse_str = ""; string decoded_Morse_str = ""; int num; int len = in_str.length(); int temp_num[100] = {0}; int cum_rev_num[100] = {0}; for(int i=0;i<len;i++){ for(int j=0;j<code_num;j++){ if(chars[j]==in_str[i]){ num = j; break; } } temp_num[i] = char_len[num]; if(num == 0) Morse_str += ".-"; else Morse_str += Morse.substr(cum_char_len[num-1],char_len[num]); } // Reverse Cumulation for(int i=0;i<len;i++){ if(i==0){ cum_rev_num[0] = temp_num[len-1]; decoded_Morse_str += chars[decode(Morse_str, 0, temp_num[len-1])]; }else{ cum_rev_num[i] = cum_rev_num[i-1] + temp_num[len-i-1]; decoded_Morse_str += chars[decode(Morse_str, cum_rev_num[i-1], temp_num[len-i-1])]; } } return decoded_Morse_str; } int main(){ int t, i=1; string in_str; cin>>t; while(t--){ cin>>in_str; cout<<i<<": "<<convt(in_str)<<endl; i++; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator