Codeforces 260B - Ancient Prophesy

时间:2023-03-09 18:56:41
Codeforces 260B - Ancient Prophesy

260B - Ancient Prophesy

思路:字符串处理,把符合条件的答案放进map里,用string类中的substr()函数会简单一些,map中的值可以边加边记录答案,可以省略迭代器访问部分。

代码:

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
map<string,int>mp;
string s;
int d[]={,,,,,,,,,,,};
bool isOK(string s)
{
if(s[]!='-'||s[]!='-')return false;
if(s[]=='-'||s[]=='-'||s[]=='-'||s[]=='-')return false;
int a=(s[]-'')*+s[]-'';
int b=(s[]-'')*+s[]-'';
if(b<=||b>)return false;
if(a<=||a>d[b-])return false;
return true;
}
int main()
{
cin>>s;
int cnt=;
string ans;
for(int i=;i<s.size()-;i++)
{
if(s[i]==''&&s[i+]==''&&s[i+]==''&&''<=s[i+]&&s[i+]<='')
{
string s1=s.substr(i-,);
if(isOK(s1))
{
string s2=s.substr(i-,);
mp[s2]++;
if(mp[s2]>cnt)
{
cnt=mp[s2];
ans=s2;
}
}
}
}
cout<<ans<<endl;
return ;
}