A1152
#include<iostream>
using namespace std;
string s;
int n,k;
bool isPrime(int x)
{
if(x==1)
return false;
for(int i=2; i*i<x; i++)
{
if(x%i==0)
return false;
}
return true;
}
int main()
{
cin >> n >> k >> s;
bool flag=false;
string first;
for(int i=0; i+k<=s.size(); i++)
{
string temp1=s.substr(i,k);
int temp2=stoi(temp1);
if(isPrime(temp2))
{
first=temp1;
flag=true;
break;
}
}
if(flag==true)
cout << first;
else
cout << 404;
return 0;
}
A1116
#include<iostream>
#include<map>
#include<unordered_set>
using namespace std;
const int maxn=10010;
int n,k;
map<int,int> s;
unordered_set<int> s1;
bool isPrime(int x)
{
for(int i=2; i*i<=x; i++)
{
if(x%i==0)
return false;
}
return true;
}
int main()
{
cin >> n;
int temp1;
for(int i=1; i<=n; i++)
{
cin >> temp1;
s[temp1]=i;
s1.insert(temp1);
}
bool inq[maxn]={
false};
cin >> k;
int temp2;
for(int i=0; i<k; i++)
{
cin >> temp2;
if(s1.count(temp2)==0)
{
printf("%04d: Are you kidding?\n",temp2);
}
else
{
if(inq[temp2]==false)
{
if(s[temp2]==1 || s[temp2]==0)
printf("%04d: Mystery Award\n",temp2);
else if(isPrime(s[temp2]))
printf("%04d: Minion\n",temp2);
else
printf("%04d: Chocolate\n",temp2);
inq[temp2]=true;
}
else
{
printf("%04d: Checked\n",temp2);
}
}
}
return 0;
}
A1112
#include<iostream>
using namespace std;
const int maxn=200;
int k;
string s;
int st[maxn];
int main()
{
cin >> k >> s;
for(int i=0; i<s.size(); i++)
{
int j=i+1;
while(j<s.size() && s[i]==s[j])
{
j++;
}
int len=j-i;
if(len%k)
{
st[s[i]]=1;
}
i=j-1;
}
string res;
for(int i=0; i<s.size(); i++)
{
if(!st[s[i]])
{
cout << s[i];
st[s[i]]=2;
}
if(st[s[i]]==1)
{
res+=s[i];
}
else
{
res+=s[i];
i+=k-1;
}
}
cout << endl << res << endl;
}
A1104
#include<iostream>
using namespace std;
const int maxn=101111;
int n;
long double all=0;
int main()
{
cin >> n;
double temp;
for(int i=1; i<=n; i++)
{
cin >> temp;
all+=temp*i*(n-i+1);
}
printf("%.2Lf",all);
return 0;
}