码迷,mamicode.com
首页 > 其他好文 > 详细

洛古最简单50题解(31-40)

时间:2019-07-10 13:34:55      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:lin   oid   float   素数   amp   成绩   cstring   out   hit   

做为一名新手,首先要过一过题,找找成就感。(大佬略过)。下面附上洛古最简单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.

洛古最简单50题解(31-40)

标签:lin   oid   float   素数   amp   成绩   cstring   out   hit   

原文地址:https://www.cnblogs.com/aybengwa/p/11163270.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!