acwing第 66 场周赛
昨晚打了acwing的第66周赛,不出所料是顺利签到,仅签到
说一下题目:https://www.acwing.com/activity/content/problem/content/7449/
题目很直白,给定一个16位数要求末尾如果可以被二整除就是0否则是1
我的思路也很直白:16转10判断奇偶输出:
参考代码:
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define int long long 4 #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 5 signed main() 6 { 7 IOS; 8 char ch[50]; 9 cin>>ch; 10 int len=strlen(ch); 11 int sum=0,k=0; 12 for (int i = len-1; i >= 0; i--) { 13 if (ch[i] >= '0' && ch[i] <= '9') sum += (ch[i] - '0') * pow(16, k++); 14 else sum += (ch[i] - 'A' + 10) * pow(16, k++); 15 } 16 sum=sum%10; 17 if(sum==0) 18 cout<<0; 19 else if(sum%2==0) 20 cout<<0; 21 else 22 cout<<1; 23 return 0; 24 }
第二题:https://www.acwing.com/problem/content/4610/
给定一个连续字符串,这个字符串由大写字母和‘?'构成,题目要求将问号转化成这个字符串中未出现的大写字母并且这个字符串中要包括一个长度为26的连续子串;
题目分析:首先如果这个字符串要是出现重复字母就是不合理的方案,如果没有,要将?转化为未出现的字符,同时在每个区间内也要包括这样的规则,如果找到一个长度为26的连续子串之后,其余?直接变成任意字母就可以了
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define int long long 4 #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 5 signed main() 6 { 7 IOS; 8 string s; 9 unordered_set<char>hs;//哈希表,用来记录出现的字符 10 vector<char>co;//用来记录没有出现的字符 11 getline(cin,s); 12 for(int i=25;i<s.size();i++)//枚举区间 13 { 14 bool flag=true; 15 hs.clear(); 16 for(int j=i-25;j<=i;j++)//枚举区间内每个字符 17 { 18 if(hs.count(s[j])&&s[j]!='?')//如果在hash中找到这个字符并且不是问号的前提下, 就说明有字符出现多次,不合理 19 { 20 flag=false;//置为不合理方案 21 break; 22 } 23 else//找不到往hs中插入 24 hs.insert(s[j]); 25 } 26 if(flag)//如果存在合理方案 27 { 28 co.clear(); 29 for(char ch='A';ch<='Z';ch++)//枚举没有出现的字符并且插进存的地方 30 { 31 if(!hs.count(ch)) 32 co.push_back(ch); 33 } 34 for(int j=i-25,cnt=0;j<=i;j++)//每个字符如果是?,就用co中的字符来替换 35 { 36 if(s[j]=='?') 37 s[j]=co[cnt++]; 38 } 39 for(auto& c:s)//已经满足了一个长度为26的连续子串,其余的问好只要是?就用随便一个字符替代即可 40 { 41 if(c=='?') 42 c='A'; 43 } 44 cout<<s<<endl; 45 return 0; 46 } 47 } 48 cout<<-1<<endl; 49 return 0; 50 }
不得不说y总真的强,yyds
第三题就免了
本文来自博客园,作者:江上舟摇,转载请注明原文链接:https://www.cnblogs.com/LQS-blog/p/16633075.html