标签:head namespace pow == 查表 message lib 每日一题 mes
题意:阅读理解难度一道比一道难orz。手摸了好久样例
题解:
读入:大循环用getline读入header顺便处理一下,
里面再写两重循环,外层一次读三个串,内层一次读num个串。
之后就查表,线性输出即可。
关于判断11111,我用了换底公式:log(id + 1) / log(2) == num + 1 && pow(2, log(id + 1) / log(2))
关于读入,我写了个getnchar的函数,封装一下getchar()
虽然是final模拟(签到orz)题,码量不大嘛
#include<iostream> #include<string> #include<cstring> #include<cmath> #include<cstdio> #include<cstdlib> #include<stdio.h> #include<algorithm> #include<set> #include<bitset> #include<map> using namespace std; #define rep(i,j,k) for(int i = (int)j;i <= (int)k;i ++) #define per(i,j,k) for(int i = (int)j;i >= (int)k;i --) #define debug(x) cerr<<#x<<" = "<<(x)<<endl #define mmm(a,b) memset(a,b,sizeof(a)) #define pb push_back #define eps 1e-7 typedef long long ll; const int maxn = 1e5 + 4; const ll mod = 1e9 + 7; //map<int, char> mmp; char mmp[8][256]; string line; void match(string s) { int len = s.length(); int num = 0, id = 0; int val = 0; rep(i, 0, len - 1) { mmp[num][id] = s[i]; id++; if (log(id + 1) / log(2)==num+1&&pow(2, log(id + 1) / log(2)) == id + 1)id = 0, num++; } } int getnchar(int n) { int cnt = n; int now=0; while (cnt--) { char c = getchar(); if (c == ‘\n‘) { cnt++; continue; } now *= 2; now += c- ‘0‘; } return now; } int main() { while (getline(cin, line)) { mmm(mmp, 0); match(line); int num; while (num=getnchar(3)) { num--; while (1) { int id= getnchar(num+1); if (log(id + 1) / log(2) == num + 1 && pow(2, log(id + 1) / log(2)))break; cout << mmp[num][id]; } } cout << endl; getchar(); } } /* TNM AEIOU 0010101100011 1010001001110110011 11000 $#**0100000101101100011100101000 TNM AEIOU 001 0T 1 011 000A 111 010 00N 10‘ ‘ 01M 11 011 001E 111 000 TAN ME 0T, 00N, 01M, 10‘ ‘, 000A, 001E, 010I, 011, 100, 101, 110, 0000, 0001 */
【每日一题】 UVA - 213 Message Decoding 模拟解码+读入函数+阅读题
标签:head namespace pow == 查表 message lib 每日一题 mes
原文地址:https://www.cnblogs.com/SuuT/p/9457427.html