Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:我这种菜鸟做这道水题也花了不少时间。。。贴一下代码吧。。

Posted by yyulei at 2017-09-04 16:52:40 on Problem 1051
In Reply To:我这种菜鸟做这道水题也花了不少时间。。。贴一下代码吧。。 Posted by:david1991 at 2013-01-29 09:34:32
> //G++
> #include<iostream>
> #include<vector>
> #include<string>
> using namespace std;
> struct morse_code
> {
>     string ch;
>     string code;
>     
> };
> struct morse_code morse_code[50];
> 
> int main()
> {
>     morse_code[0].ch="A";
>     morse_code[0].code=".-";
>    
>     morse_code[1].ch="B";
>     morse_code[1].code="-...";
>     
>      morse_code[2].ch="C";
>     morse_code[2].code="-.-.";
>     
>      morse_code[3].ch="D";
>     morse_code[3].code="-..";
>    
>      morse_code[4].ch="E";
>     morse_code[4].code=".";
>    
>      morse_code[5].ch="F";
>     morse_code[5].code="..-.";
>   
>      morse_code[6].ch="G";
>     morse_code[6].code="--.";
>     
>      morse_code[7].ch="H";
>     morse_code[7].code="....";
>     
>      morse_code[8].ch="I";
>     morse_code[8].code="..";
>    
>      morse_code[9].ch="J";
>     morse_code[9].code=".---";
>   
>      morse_code[10].ch="K";
>     morse_code[10].code="-.-";
>     
>      morse_code[11].ch="L";
>     morse_code[11].code=".-..";
> 
>      morse_code[12].ch="M";
>     morse_code[12].code="--";
>     
>      morse_code[13].ch="N";
>     morse_code[13].code="-.";
>      
>      morse_code[14].ch="O";
>     morse_code[14].code="---";
>   
>      morse_code[15].ch="P";
>     morse_code[15].code=".--.";
>   
>      morse_code[16].ch="Q";
>     morse_code[16].code="--.-";
>   
>      morse_code[17].ch="R";
>     morse_code[17].code=".-.";
>     
>      morse_code[18].ch="S";
>     morse_code[18].code="...";
>    
>      morse_code[19].ch="T";
>     morse_code[19].code="-";
>    
>      morse_code[20].ch="U";
>     morse_code[20].code="..-";
>      
>      morse_code[21].ch="V";
>     morse_code[21].code="...-";
>    
>      morse_code[22].ch="W";
>     morse_code[22].code=".--";
>    
>      morse_code[23].ch="X";
>     morse_code[23].code="-..-";
>      
>      morse_code[24].ch="Y";
>     morse_code[24].code="-.--";
>     
>      morse_code[25].ch="Z";
>     morse_code[25].code="--..";
>     
>      morse_code[26].ch="_";
>     morse_code[26].code="..--";
>     
>      morse_code[27].ch=",";
>     morse_code[27].code=".-.-";
>     
>      morse_code[28].ch=".";
>     morse_code[28].code="---.";
>     
>      morse_code[29].ch="?";
>       morse_code[29].code="----";
>      
>      
>      string encoded_message;
>      string morse="";
>      vector<string> morse_set; 
>      
>     
>      int n;
>      cin>>n;
>      const int MAX=n;
>      vector<vector<int> > num_pause(MAX); 
>      for(int i=0;i<n;i++)
>      {
>         cin>>encoded_message;
>         for(int j=0;j<encoded_message.size();j++)
>         {
>            for(int k=0;k<30;k++)
>            {
>                if(encoded_message[j]==morse_code[k].ch[0])
>                {
>                   morse+=morse_code[k].code;
>                   num_pause[i].push_back(morse_code[k].code.size());
>                }
>            }
>            
>         }
>         morse_set.push_back(morse);
>         morse="";
>          
>         
>      }
>     
>     string sub;
>      string result="";
>      for(int i=0;i<n;i++)
>      {
>         for(int j=num_pause[i].size()-1;j>=0;j--)
>         {
>             sub=morse_set[i].substr(0,num_pause[i][j]);
>             morse_set[i].erase(0,num_pause[i][j]);
>             for(int k=0;k<30;k++)
>             {
>                 if(sub==morse_code[k].code)
>                 {
>                    result+=morse_code[k].ch;
>                 }
>             }
>         }
>         cout<<(i+1)<<": "<<result<<endl;
>         result="";
>         
>      }
>     
>     
>     return 0;
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator