[模拟] Lattice's basics in digital electronics

题目链接:https://www.jisuanke.com/contest/1556/105551

代码如下:

  1 #include <iostream>
  2 #include <bits/stdc++.h>
  3 using namespace std;
  4 const int maxn = 1e5+50;
  5 map<string,int> mp;
  6 map<char,int>mpp;
  7 int m,n,x;
  8 string str;
  9 string ss;
 10 void init()
 11 {
 12     mpp[‘A‘]=10,mpp[‘a‘]=10;
 13     mpp[‘B‘]=11,mpp[‘b‘]=11;
 14     mpp[‘C‘]=12,mpp[‘c‘]=12;
 15     mpp[‘D‘]=13,mpp[‘d‘]=13;
 16     mpp[‘E‘]=14,mpp[‘e‘]=14;
 17     mpp[‘F‘]=15,mpp[‘f‘]=15;
 18 }
 19 void change(string s)
 20 {
 21     int len=s.size();
 22     if(len<9)
 23         return;
 24     else
 25     {
 26         int cnt=0;
 27         for(int i=0;i<len-1;i++)
 28         {
 29             if(s[i]==‘1‘)
 30                 cnt++;
 31         }
 32         if(cnt%2==1&&s[len-1]==‘0‘)
 33         {
 34             for(int i=0;i<8;i++)
 35                 ss+=s[i];
 36         }
 37         else if(cnt%2==0&&s[len-1]==‘1‘)
 38         {
 39             for(int i=0;i<8;i++)
 40                 ss+=s[i];
 41         }
 42         //cout << ss << endl;
 43     }
 44 }
 45 string turn(int x)
 46 {
 47     int a[10];
 48     string cc;
 49     int cnt=0;
 50     while(x)
 51     {
 52         a[cnt++]=x%2;
 53         x/=2;
 54     }
 55     for(int i=cnt-1;i>=0;i--)
 56     {
 57         cc+=a[i]+‘0‘;
 58     }
 59     int len=cc.size();
 60     while(len<4)
 61     {
 62         cc=‘0‘+cc;
 63         len++;
 64     }
 65     return cc;
 66 }
 67 int main()
 68 {
 69     //cout << turn(1) << endl;
 70     int T;
 71     scanf("%d",&T);
 72     init();
 73     while(T--)
 74     {
 75         mp.clear();
 76         scanf("%d %d",&m,&n);
 77         for(int i=0;i<n;i++)
 78         {
 79             cin>>x>>str;
 80             mp[str]=x;
 81         }
 82         cin>>str;
 83         //cout << str << endl;
 84         string temp="";
 85         for(int i=0;i<str.size();i++)
 86         {
 87             if(str[i]>=‘0‘&&str[i]<=‘9‘)
 88             {
 89
 90                 string cc=turn(str[i]-‘0‘);
 91                 temp+=cc;
 92             }
 93             else
 94             {
 95                 string cc=turn(mpp[str[i]]);
 96                 temp+=cc;
 97             }
 98         }
 99         //cout << temp << endl;
100         int pos=0;
101         string s="";
102         ss="";
103         for(int i=0;i<temp.size();i++)
104         {
105             pos++;
106             s+=temp[i];
107             if(pos==9)
108             {
109                 change(s);
110                 pos=0;
111                 s="";
112             }
113         }
114         string ans="";
115         string c="";
116         //cout << ss << endl;
117         for(int i=0;i<ss.size();i++)
118         {
119             c+=ss[i];
120             if(mp.find(c)!=mp.end())
121             {
122                 //cout << c << endl;
123                 char ch=mp[c];
124                 ans+=ch;
125                 c="";
126             }
127         }
128         for(int i=0;i<m;i++)
129         {
130             printf("%c",ans[i]);
131         }
132         printf("\n");
133     }
134     //cout << "Hello world!" << endl;
135     return 0;
136 }
137 /*
138 1
139 8 3
140 49 0001
141 50 01001
142 51 011
143 14DB24722698
144 */

[模拟] Lattice's basics in digital electronics

原文地址:https://www.cnblogs.com/SoulSecret/p/9610095.html

时间: 2024-08-30 17:04:16

[模拟] Lattice's basics in digital electronics的相关文章

【ACM-ICPC 2018 沈阳赛区网络预赛 I】Lattice&#39;s basics in digital electronics

[链接] 我是链接,点我呀:) [题意] 每个单词的前缀都不同. 不能更明示了... 裸的字典树. 模拟一下.输出一下就ojbk了. [题解] #include <bits/stdc++.h> #define LL long long #define rep1(i,a,b) for (int i = a;i <= b;i++) #define rep2(i,a,b) for (int i = a;i >= b;i--) #define all(x) x.begin(),x.end(

Lattice&#39;s basics in digital electronics

LATTICE is learning Digital Electronic Technology. He is talented, so he understood all those pieces of knowledge in 10^{-9}10?9 second. In the next 10^{-9}10?9 second, he built a data decoding device that decodes data encoded with his special binary

ACM-ICPC 2018 沈阳赛区网络预赛

A. Gudako and Ritsuka 留坑 B. Call of Accepted 留坑 C. Convex Hull 留坑 D. Made In Heaven 留坑 E. The cake is a lie 留坑 F. Fantastic Graph 留坑 G. Spare Tire 留坑 H. Hamming Weight 留坑 I. Lattice's basics in digital electronics 留坑 J. Ka Chang 留坑 K. Supreme Number

2018 ACM 网络选拔赛 沈阳赛区

B. Call of Accepted 1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <time.h> 6 #include <string> 7 #include <set> 8 #include <map> 9 #include <list> 10 #incl

Using QEMU for Embedded Systems Development

http://www.opensourceforu.com/2011/06/qemu-for-embedded-systems-development-part-1/ http://www.opensourceforu.com/2011/07/qemu-for-embedded-systems-development-part-2/ http://www.opensourceforu.com/2011/08/qemu-for-embedded-systems-development-part-3

Tecplot Chorus 2015 R2 Win64 &amp; Linux64 2CD CFD模拟分析

Tecplot Chorus 2015 R2 Win64 & Linux64 2CD CFD模拟分析Tecplot Chorus为工程师分析大量模拟数据提供了一个崭新的工具.Tecplot Chorus集成了元数据分析.后处理和模拟数据管理功能,方便 于加快工程决策的制定.在CFD研究中,Tecplot Chorus使工程师能更加简单地发现趋势和异常情况,同时洞察引起这些变化的潜在的流动现象.通过帮助工程师协作分析大量模拟数据,Tecplot Chorus将会有助于工程师更快地获得更加有信息的结

科技文献检索

The Fundamentals of Three-Phase Power Measurements Application Note Introduction Although single-phase electricity is used to supply common domestic and office electrical appliances, three-phase alternating current (a.c.) systems are almost universal

Transistor 晶体管 场效应 双极型 达林顿 CMOS PMOS BJT FET

Transistor Tutorial Summary Transistor Tutorial Summary Bipolar Junction Transistor Tutorial We can summarise this transistors tutorial section as follows: The Bipolar Junction Transistor (BJT) is a three layer device constructed form two semiconduct

计算机电子书 2018 BiliDrive 备份

下载方式 根据你的操作系统下载不同的 BiliDrive 二进制. 执行: bilidrive download <link> 链接 文档 链接 Webpack 中文指南.epub (409.01 KB) bdrive://ce58b7b58292296a61a97de1f89c62b66da24ab6 OpenIntro Statistics 3e.pdf (7.17 MB) bdrive://ef01910ee34f0a1c91d9435f750a49c6ac1bc5fa AngularJ