###### tags: `實習題目` # Decoder ## Description 請寫一函式`Decoder`輸入一**數字字串**(注意:請使用string),將它翻譯成一句子 > Hint: > 使用Ascii code > 範圍是英文大小寫和空白 > 可以上網查詢"字串轉數字"的方法( ͡° ͜ʖ ͡°) ## Sample Input 1 ``` 83117110110121 ``` ## Sample Output 1 ``` Sunny ``` ## Sample Input 2 ``` 74657569321051153267117116101 ``` ## Sample Output 2 ``` JAKE is Cute ``` <!--改編自careerhack和資工onlinejudge 答案(by Hsu17): #include<iostream> #include<string> using namespace std; void decoder(string num) { int number[num.length()]; string c,newstr=""; for(int i=0;i<num.length();i++) { c=num[i]; number[i]=stoi(c); } for(int i=0;i<num.length();i+=2) { // cout<<number[i]; int num_d=number[i]*10+number[i+1],len=0; if(num_d==32) { newstr+=" "; } if(num_d>=65&&num_d<=90) { newstr+=num_d; } else if(num_d>=97&&num_d<=99) { newstr+=num_d; } else if(num_d==10||num_d==11||num_d==12) { num_d=number[i]*100+number[i+1]*10+number[i+2]; i++; newstr+=num_d; } } cout<<newstr<<endl; } int main() { string code; cin>>code; decoder(code); } --!>