洛古最简单50题解(41-50)
做为一名新手,首先要过一过题,找找成就感。(大佬略过)。下面附上洛古最简单50题(大佬略过)。以及最麻烦 ac代码,至少ac了。
no.41 p2676 超级书架
#include<iostream>
#include<algorithm>
using
namespace std;
int main()
{
int i,n,b,ans,m;
int a[100001];
cin>>n>>b;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
i=n;
ans=0;
m=0;
while (m<b)
{
m+=a[i--];
++ans;
}
cout<<ans-1<<endl;
return
0;
}
no.42 p2788 数学1(math1)- 加减算式
#include<iostream>
using
namespace std;
int ans,t;
int main()
{
while(cin>>t) ans+=t;
cout<<ans;
return
0;
}
no.43 p2955 [usaco09oct]奇数偶数even odd
#include<iostream>
#include<cstring>
using
namespace std;
int main()
{
long
long n,i;
cin>>n;
string a;
for (i=1; i<=n; i++)
{
cin>>a;
if ((a[a.size()-1]-'0')%2==0)
{
cout<<"even"<<endl;
}
else
{
cout<<"odd"<<endl;
}
}
return
0;
}
no.44 p3150 pb的游戏(1)
#include<iostream>
using
namespace std;
int main()
{
int n,t;
int a[100001];
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>t;
if (t % 2 ==0)
a[i]=1;
else
a[i]=0;
}
for (int i=1; i<=n;i++)
{
if (a[i]==1)
cout<<"pb wins\n";
else
cout<<"zs wins\n";
}
return
0;
}
no.45 p3912 素数个数
#include<cmath>
#include<iostream>
using
namespace std;
int main()
{
int n;
cin>>n;
}
no.46 p3954 成绩
#include<cstdio>
using
namespace std;
int main()
{
float a,b,c,n;
scanf("%f%f%f",&a,&b,&c);
n=a*0.2+b*0.3+c*0.5;
printf("%.0f",n);
return
0;
}
no.47 p4325 [coci2006-2007#1] modulo
//1:
#include<iostream>
using
namespace std;
int main()
{
int a[10],n=0;
for (int i=1;i<=10;i++)
{
cin>>a[i];
a[i]=a[i]%42;
}
for (int i=1;i<=10;i++)
{
for (int j=1;j<=10;j++)
{
if(a[i]==a[j] && i!=j)
{
a[i]=-1;
}
}
if (a[i]!=-1)
{
n++;
}
}
cout<<n<<endl;
}
//2:
#include<iostream>
using
namespace std;
int main()
{
int a[10],n=0;
for (int i=1;i<=10;i++)
{
cin>>a[i];
a[i]%=42;
for (int j=1;j<=i;j++)
{
if(a[i]==a[j] && i!=j)
{a[i]=-1;}
}
}
for (int i=1;i<=10;i++)
if (a[i]!=-1)
{n++;}
cout<<n<<endl;
}
//3:
#include<iostream>
using
namespace std;
int main()
{
int a[10],n=0;
for (int i=1;i<=10;i++)
{
cin>>a[i];
a[i]%=42;
for (int j=1;j<=i;j++)
if(a[i]==a[j] && i!=j) {a[i]=-1;}
if (a[i]!=-1){n++;}
}
cout<<n<<endl;
}
no.48 p4413 [coci2006-2007#2] r2
#include<cstdio>
using
namespace std;
int main()
{
float s,r1,r2;
scanf("%f%f",&r1,&s);
r2=(s-r1/2)*2;
printf("%.0f",r2);
return
0;
}
no.49 [洛古]t48131 【高精度】求n!的值
#include <bits/stdc++.h>
int n,a[100000],l1 =1;
void input_data()
{
scanf("%d",&n);
for (int i = 1; i <= 999;i++)
a[i] = 0;
a[1] = 1;
}
void get_ans()
{
for (int i = 1;i <= n;i++)
{
int x = 0;
for (int j = 1;j <= l1;j++)
{
a[j] = a[j] *i + x;
x = a[j] / 10;
a[j] = a[j] % 10;
}
while ( x > 0)
{
l1++;
a[l1] += x;
x = a[l1] / 10;
a[l1] = a[l1] % 10;
}
}
}
void output_ans()
{
for (int i = l1;i >= 1;i--)
printf("%d",a[i]);
}
int main()
{
input_data();
get_ans();
output_ans();
return
0;
}
no.50 ??
#include<bits/stdc++.h>
using
namespace std;
???
int main(){
--???????--
return
0;
}
第五十题,我故意设置了一个悬念,绝对不会告诉你,是因为之前把49数成了50,
欢迎大家把自己的想法发给我:3503344701@qq.com.
下一篇: 汉字无法插入数据库解决方案