标签:find str bsp opened att pos event close size
题目链接: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
标签:find str bsp opened att pos event close size
原文地址:https://www.cnblogs.com/SoulSecret/p/9610095.html