szyy的竞赛总结
前言
更新日志
第一部分:语法
1.顺序结构
1.输出
经典例题:
#15. Hello World
这是每一个初学者的一道世界级水题 (请忽略本蒟蒻的10条\(\color{E74C3C}\text{WA}\)记录)
这里给新手提示一下常见错误:
1、写成:Hello world!或 Hello,world!
2、没有正确使用英文输入法
3、单词打错了,比如:using namepsace std;或cuot<<"Hello World";
\(\color{52C41A}\text{AC}\)代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
cout<<"Hello World";
return 0;
}
更多输出练习题:
#16. 输出 * 形图形
#17. 超级简单计算
2.输入
经典例题:
#1. A + B Problem
这道题超级简单,所以不太需要讲解和提示
\(\color{52C41A}\text{AC}\)代码:
#include <bits/stdc++.h>
using namespace std;
int a,b;
int main ()
{
cin>>a>>b;
cout<<a+b;
return 0;
}
更多输入练习题:
#24. 海伦公式求三角形面积
#25. 口渴的大象
#26. 交换两个数的顺序
3.常量
经典习题:
#1404. 圆的周长
常量的使用方法如下:
const 数据类型 变量名=常数;
\(\color{52C41A}\text{AC}\)代码:
#include <bits/stdc++.h>
using namespace std;
const double PI=3.14;
int r;
double ans;
int main()
{
cin>>r;
ans=2*PI*r;
cout<<ans;
return 0;
}
4.变量
经典习题 (还是它):
#1404. 圆的周长
变量的使用方法如下:
数据类型 变量名(=常数);
\(\color{52C41A}\text{AC}\)代码:
#include <bits/stdc++.h>
using namespace std;
const double PI=3.14;
int r;
double ans;
int main()
{
cin>>r;
ans=2*PI*r;
cout<<ans;
return 0;
}
2.分支结构
1.输出
经典例题:
#37. 判断一个三位数是否为水仙花数
这个是基础的分支结构,较为简单,不予太多讲解,只要理解水仙花数的定义即可
\(\color{52C41A}\text{AC}\)代码:
#include <bits/stdc++.h>
using namespace std;
int a,b,c,s;
int main ()
{
cin>>s;
a=s/100;
b=s/10%10;
c=s%10;
if(a*a*a+b*b*b+c*c*c==s)//判断这个三位数是否为水仙花数
{
cout<<"Y";
}
else
{
cout<<"N";
}
return 0;
}