据说正式赛要难一点。
符合条件的数
可能输入的数就满足条件的。
#include <iostream>
using namespace std;
long long k ;
bool check(long long x)
{ int cnt = 0;
while(x)
{
if(x % 10 == 3) cnt ++;
x/=10;
}
return cnt == k;
}
int main()
{
long long n;
cin >> n >> k;
for(long long i = n ;;i++)
{
if(check(i))
{
cout << i << endl;
break;
}
}
return 0;
}
选代表
#include <iostream>
#include <map>
using namespace std;
map<int,int>m;
int main()
{
int n;
cin >> n;
for(int i = 0; i < n ; i++)
{
int a;
cin >> a;
if(m[a] == 0)
{
cout << a << ' ';
m[a] = 1;
}
}
return 0;
}
成绩统计
#include <bits/stdc++.h>
using namespace std;
struct node {
string name;
int a,b,sum,id;
}e[1000];
int cmp(node x,node y)
{
if(x.sum != y.sum) return x.sum > y.sum;
else return x.id < y .id;
}
int main()
{
int n;
cin >> n;
for(int i = 0; i< n ;i++)
{ e[i].id = i;
cin >> e[i].name >> e[i].a >> e[i].b;
double c = (sqrt(e[i].b)*10);
if(c == (int)c) e[i].b = (int)c;
else {
e[i].b = (int)c + 1;
}
e[i].sum = round(e[i].b *0.6 + e[i].a *0.4);
}
sort(e,e+n,cmp);
for(int i = 0; i<n;i++)
{
cout << e[i].name << ' ' << e[i]. sum << endl;
}
return 0;
}
背答案
#include <iostream>
using namespace std;
struct node{
string w,d;
}e[1000];
int main()
{
int n,q;
cin >> n >> q;
for(int i = 0; i < n;i++)
{
cin >> e[i].w >> e[i].d;
}
while(q--)
{
int cnt = 0;
string a;
cin >> a;
int s;
for(int i =0;i < n;i++)
{
if(e[i].w == a)
{
s = i;break;
}
}
for(int i = 0;i < 4;i++)
{
string b;
cin >> b;
if(e[s].d == b)
{
cout << (char)(65+cnt) << endl;
}
cnt ++;
}
}
return 0;
}
击鼓传花
#include <iostream>
using namespace std;
const int N = 1000010;
int m1[N];
int n,m,k;
inline int read()
{
int x = 0, f = 1;
char ch = getchar();
while(ch > '9' || ch < '0'){if(ch == '-')f = -1;ch = getchar();}
while(ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}
return x * f;
}
void check(int x)
{
for(int i = x;;i = (i + k) % n)
{
if(m1[i] == 1) break;
m1[i] = 1;
}
}
int main()
{
n = read(),m = read(),k =read();
while(m--)
{
int j;
j = read();
if(m1[j] == 0)
check(j);
}
int ans= 0;
for(int i = 0;i < n;i++)
{
if(m1[i] == 0) ans++;
}
printf("%d\n",ans);
return 0;
}