发布作者: ZHWEI
百度收录: 正在检测是否收录...
作品采用: 《 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 》许可协议授权
#include<bits/stdc++.h>
using namespace std;
int main()
{
return 0;
}
#include <bits/stdc++.h>
考察字符类型 char 、基础输入输出换行
字符单引号 只能保存一个字符
字符串双引号 可保存一个及以上个字符
主要使用:char cin cout endl
c++换行必须endl 分多个cout输出没用 会黏一块!!
#include <iostream>
using namespace std;
int main(){
string s;
cin >> s;
cout << " " << s << endl ;
cout << " " << s << s <<s << endl ;
cout << s << s << s << s << s << endl ;
return 0;
}
考察输入输出 正常格式cout即可 编译器会计算答案
主要使用:int cin cout
#include <iostream>
using namespace std;
int main (){
int a , b ,c ;
cin >> a >> b >> c;
cout << (a+b)*(c-b);
return 0;
}
考察 “或” || if else 的运用
主要使用:int cin if || else
#include <iostream>
using namespace std;
int main(){
int a;
cin >> a;
if(a == 3 || a == 1 || a == 5)
{
cout << "NO";
}
else
{
cout << "YES";
}
return 0;
}
主要考察while if else & 运算符 的运用
int可以存1000000000(10^9) 更大使用“long long”
#include <iostream>
using namespace std;
int main(){
int a ;
cin >> a;
while (a > 1)
{
if (a % 2 == 0)
{
cout << a << "/2=" << a / 2 <<endl;
a /= 2;
}
else
{
cout << a << "*3+1=" << a*3+1 <<endl;
a = a * 3 + 1;
}
}
cout << "End";
return 0;
}
完全平方数:某个数的平方
考察数位提取
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, a, b, c, x;
int num = 1;
cin >> n;
for (int i = 100; i <= 999; i++)
{
x = (int)sqrt(i);
if (x * x == i)
{
a = i / 100;
b = (i / 10) % 10;
c = i % 10;
if (a == b || b == c || a == c)
{
if (num == n)
{
cout << i;
break;
}
num++;
}
}
}
return 0;
}
/*
/*大前提:三位数*/
bai = shu/100; //百位 求这个三位数有几个100
shi = shu/10%10//十位 把这个三位数的百位和十位拎出来 变成一个所谓的“两位数” 再除以10 取个位(此时的个位就是十位)
ge = shu%10 //个位 很简单 别问为啥
*/
—— 评论区 ——