520 钻石争霸赛 题解

7-1 考试周

#include<bits/stdc++.h>
using namespace std;
int main()
{
double a,b,c;
cin>>a>>b;
c=a/b;
printf("%.0lf/%.1f=%.0f",a,c,b);
}


7-2 真的恭喜你

if比较输出

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
if(n>=90)printf("gong xi ni kao le %d fen!",n);
else printf("kao le %d fen bie xie qi!",n);
}


7-3 平均成绩

1和0分别代表男女

#include<bits/stdc++.h>
using namespace std;
double sum1;
double sum2;
double ans1;
double ans2;
int main()
{
double n;
double a,b;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a>>b;
if(a==1)
{
sum1++;
ans1+=b;
}
else
{
sum2++;
ans2+=b;
}
}
if(sum1==0)
{
printf("%.1lf X %.1lf",(ans1+ans2)/n,ans2/sum2);
}
else if(sum2==0)
{
printf("%.1lf %.1lf X",(ans1+ans2)/n,ans1/sum1);
}
else
{
printf("%.1lf %.1lf %.1lf",(ans1+ans2)/n,ans1/sum1,ans2/sum2);
}
}


7-4 古风A+B

#include<bits/stdc++.h>
using namespace std;
double sum1;
double sum2;
double ans1;
double ans2;
int w[100];
int main()
{
long long a,b,c;
cin>>a>>b;
c=a+b;
int ans=0;
if(c<0)
{

cout<<"-"<<endl;
c=c*-1;
}
if(c==0)
{
cout<<"0";
return 0;
}
while(c)
{
w[++ans]=c%10;
c/=10;
}
for(int i=ans;i>=1;i--)
{
cout<<w[i]<<endl;
}
}


7-5 猜近似数字

#include<bits/stdc++.h>
using namespace std;
double b=0,g=0;
double sum;
int sumb,sumg;
int main()
{
string a,b;
int c[1004];
cin>>a;
char ch=getchar();
while(cin>>b&&b!="-1")
{
//	cout<<"--"<<" "<<b<<endl;
memset(c,0,sizeof(c));
ch=getchar();
if(a.length()!=b.length())cout<<"No"<<endl;
else
{
//			cout<<"***"<<" "<<b<<endl;
for(int i=0;i<a.length();i++)
{
//			printf("b[a]-a[]=%d\n ",abs(a[i]-b[i]) );
if(a[i]<b[i])
c[i]=b[i]-a[i];
else
c[i]=a[i]-b[i];
//			cout<<" c[i]="<<c[i]<<endl;
}
bool f=0;
for(int i=0;i<=a.length();i++)
{
//		cout<<"i="<<i<<endl;
if(c[i]>1)
{
cout<<"No"<<endl;
f=0;
break;

}
else if(c[i]==1&&f==0)
{
f=1;
}
else if(c[i]==1&&f==1)
{
cout<<"No"<<endl;
f=0;
break;
}

}
if(f==1)cout<<"Yes"<<endl;
}

}

}


#include<bits/stdc++.h>
using namespace std;
string a,b;
int n;
bool boolean()
{
int l=a.size();
bool f=0; for(int i=0;i<l;i++){
if(abs(a[i]-b[i])==0){ continue;
}
else if(abs(a[i]-b[i])==1&&f==0){ f=1; }else return 0; }return 1; }int main(){ cin>>a; while(1){ cin>>b; if(b=="-1") break; if(b.size()!=a.size()){ printf("No\n"); continue; }if(boolean()) printf("Yes\n"); else printf("No\n"); }return 0; }


7-6 随机输一次

**#include<bits/stdc++.h>
using namespace std;
int k[10006];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>k[i];
char ch;
ch=getchar();
char s[13];
int ans=1;
int sum=0;
bool f=0;
while(~scanf("%s",s))
{
sum++;
if(ans>n)ans%=n;
if(k[ans]+1==sum)
{
f=1;
ans++;
sum=0;
//	cout<<"-----"<<endl;
}
else f=0;
if(s[0]=='E')break;
if(s[0]=='C')
{
if(f==1)cout<<"JianDao"<<endl;
else cout<<"Bu"<<endl;
}
else if(s[0]=='J')
{
if(f==1)cout<<"Bu"<<endl;
else cout<<"ChuiZi"<<endl;
}
else if(s[0]=='B')
{
if(f==1)cout<<"ChuiZi"<<endl;
else cout<<"JianDao"<<endl;
}
ch=getchar();

}
return 0;
}**


7-7 阶乘的非零尾数

2和5都有时就出现一个0，所以求min(5,2)

2和5除去即可

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int num1,num2;
int n,k;
int main(){
cin>>n>>k;
int n1=n;
while(n1){

num1+=n1/5; //计算n1中因数5的个数
n1=n1/5; //

}
int num=num1;
num2=num1;
ll mod=pow(10,k);//求非零k位数
ll sum=1;
for(int i=1;i<=n;i++){

int w=i;
while(w%2==0&&num1)
{

w/=2;
num1--;
}
while(w%5==0&&num2)
{
w/=5;
num2--;
}
sum=(sum%mod*w%mod)%mod;
}
string c="%0";
c=c+(char)(k+'0')+"lld";
printf(c.data(),sum);
printf(" %d",num);
return 0;
}


7-8 三足鼎立

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int num1,num2;
int n,k;
const int maxn=1e6+4;
int a[maxn];
int main(){
int n,p;
cin>>n>>p;
for(int i=0;i<n;i++)cin>>a[i];
sort(a,a+n);
ll sum=0;
for(int i=0;i<n;i++)
{
int high=lower_bound(a,a+n,a[i]+p)-a;
int low=upper_bound(a,a+n.abs(a[i]-p))-a;
int num=high-low;
if(i>=low&&i<=high)
{
num--;
sum++num;
}

}
cout<<sum/2<<endl;
}


05-22 205

05-21 1421

05-22 103

05-21 234

05-22 133

05-21 174

05-21 275

05-21 165

05-21 120

05-21 134

03-10 355

04-09 6999

03-03 2万+

03-23 1万+

04-14 62万+

04-09 3万+

03-24 4万+

03-01 2万+

03-08 2万+

05-21 120

【PAT520 钻石争霸赛】7-4 古风A+B (15分)

©️2019 CSDN 皮肤主题: 游动-白 设计师: 上身试试