UVa 213 信息编码!模拟!
来源:互联网 发布:查看1433端口是否打开 编辑:程序博客网 时间:2024/06/06 09:59
背景:一次ac!!而且调试时间也短!!!!看来这个自定义函数,确实是一个好的方法!!构思又清晰,调试又明朗!
思路:一些单一的函数堆砌而成,每个函数有自己的功能。
学习:1.我是采用模拟手算二进制为十进制的方法,而小紫书上给出的方法似乎更简单:(这似乎透露除了字符串数转化普通数的方法)(普通二进制数,转化为十进制数就一位一位的拆分)
//assumpt that temp[] have n charnumbersint decimal=0;for(int i = 0;i < n;i++){ decimal=decimal*2 +temp[i]-'0';}
#include<stdio.h>#include<math.h>char list[248],temp[8],answer[10000];char scan(void){int count=0;char a;while((a = getchar()) != EOF && a != '\n'){list[count++] = a;}return a;}void print(int x,int n){ int y;if(n == 1) y=0;else if(n == 2) y=1+x;else if(n == 3) y=4+x;else if(n == 4) y=11+x;else if(n == 5) y=26+x;else if(n == 6) y=57+x;else if(n == 7) y=120+x;printf("%c",list[y]);}void get(int length){char a;int count=0;for(int i = 0;i < length;i++){if((a = getchar()) == '\n'){i--;}else{temp[count++] = a;}}} int calculate(int n){int ans=0;for(int i = n-1,k = 0;i >= 0;i--,k++){ans+=(temp[i]-'0')*(int)pow(2.0,(double)k);}return ans;}bool make(void){get(3);if(temp[0] == '0' && temp[1] == '0' && temp[2] == '0'){printf("\n");return true;}int n=calculate(3);while(1){get(n);bool over = false;for(int i = 0;i < n;i++) if(temp[i] != '1') over =true;if(!over){//this segmentbreak;} int a = calculate(n);print(a,n); }return false;} int main(void){ while(scan()!=EOF){ while(1) if(make()) break; getchar(); } return 0;}
0 0
- UVa 213 信息编码!模拟!
- UVA-213-Message Decoding 信息编码 基础模拟题 直观的新手思路+详细注释
- UVa 213 Message Decoding (信息编码)
- UVA 213 Message Decoding 【模拟】
- 信息解码(uva-213)
- 【编码】模拟编码
- UVa 213 Message Decoding (信息解码)
- Message Decoding 信息解码UVA 213
- UVa 213 信息解码Message Decoding
- UVA 10196 模拟题。。
- UVa 100 简单模拟
- UVa 602 简单模拟
- Uva 11039(排序+模拟)
- UVA 11039 模拟
- UVa 10189 Minesweeper (模拟)
- uva 11995 STL模拟
- uva 10205 模拟
- UVA 514 - Rails(模拟)
- uva 10720 Graph Construction
- 规避重复包含
- AJAX and testing
- 时钟周期/指令周期/机器周期/指令周期
- POJ 3122 Pie (二分+精度问题)
- UVa 213 信息编码!模拟!
- KMP字符串匹配算法
- Selenium
- redis入门到精通
- android基础--2
- WebAii - tools for Ajax
- HDU2101 A + B Problem Too【水题】
- PCB之创建焊盘
- 我的便笺本(MyNote) V1.0 Beta