1.好之者不如乐知者
最基础的输出,可以直接用 PHP
How Can We Live a Joyful Life
Without Programming
2.陈依涵的高情商体重计算器
· 输入原始体重不超过100:①不是 10 的整数倍,抹去个位 ②是,减去 10
· 超过 100 ,输出 100
#include<bits/stdc++.h>
using namespace std;
int main() {
int w;cin>>w;
cout<<"Gong xi nin! Nin de ti zhong yue wei: ";
if(w>100) cout<<"100";
else if(w%10==0) cout<<w-10;
else cout<<w/10*10;
cout<<" duo jin";
return 0;
}
3.环岛自行车赛
小心数据类型,是 double 还是 int
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;cin>>n;
int zc=0,zs=0;
for(int i=0;i<n;i++) {
int x;cin>>x;
zc+=x;
}
for(int i=0;i<n;i++) {
int t;cin>>t;
zs+=t;
}
double v=zc/(zs/60.0);
cout<<fixed<<setprecision(1)<<v;
return 0;
}
4.两位数加法练习
用双指针思想
#include<bits/stdc++.h>
using namespace std;
int main() {
string s;cin>>s;
int l=0,r=s.size()-1;
while(l<r) {
int x=(s[l]-'0')*10+s[r]-'0';
int y=(s[l+1]-'0')*10+s[r-1]-'0';
cout<<x<<"+"<<y<<"="<<x+y<<'\n';
l+=2,r-=2;
}
return 0;
}
5.配花束
一个快排,从小到大,输出数组第一个数即可
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N];
int main() {
int n;cin>>n;
for(int i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
cout<<a[0];
return 0;
}
6.数合数
合数是指在大于 1 的整数中除了能被 1 和本身整除外,还能被其他正整数整除的数。
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int g[N];
int main() {
int a,b,n;cin>>a>>b>>n;
for(int i=0;i<n;i++) {
int x;cin>>x;
for(int i=a;i<=b;i++) {
if(i%x==0) g[i]--;
}
}
int ans=0;
for(int i=a;i<=b;i++) {
if(g[i]==0) {
for(int j=2;j<=i/j;j++) {
if(i%j==0) {
ans++;
break;
}
}
}
}
cout<<ans;
return 0;
}
7.翻箱倒柜
用结构体即可
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
struct node {
int l,w,h;
string s;
}hz[N];
int main() {
int n;cin>>n;
for(int i=0;i<n;i++) cin>>hz[i].l>>hz[i].w>>hz[i].h>>hz[i].s;
int k;cin>>k;
while(k--) {
int x,y,z;cin>>x>>y>>z;
int ok=0;
for(int i=0;i<n;i++) {
if(hz[i].l==x&&hz[i].w==y&&hz[i].h==z) {
cout<<hz[i].s<<'\n';
ok=1;
}
}
if(ok==0) cout<<"Not Found\n";
}
return 0;
}