4.4基于switch语句的译码器
生活随笔
收集整理的這篇文章主要介紹了
4.4基于switch语句的译码器
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Q:已知前綴碼如右圖所示,求0/1字符串“001011101001011001”相對應的譯碼。
| a | b | c |
| 1 | 01 | 001 |
?
#include<iostream> #include<cstdio> using namespace std;int f(char *str,int n) {int i=0;while(i<18) {switch(str[i]) {case '1': printf("a"); break;case '0': {i++;switch(str[i]) {case '1':printf("b"); break;case '0': {i++;switch(str[i]) {case'1':printf("c"); break;}break;}}break;}}i++;} } int main() {char str[18]={001011101001011001};f(str,18);return 0; }出現(xiàn)了如下的結果:
?
轉載于:https://www.cnblogs.com/dd2hm/p/6749991.html
總結
以上是生活随笔為你收集整理的4.4基于switch语句的译码器的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 面向对象基础知识整理
- 下一篇: findbugs教程