22 条题解
-
0
判断是否为两位数
思路:
按常规思路,判断一个数是否为两位数,我们(py转过来的)一般用字符串长度,对
8吧但是这里是C++!
我们还没学……所以不能用字符串长度,不按常规的思路,思考一下,两位数的范围是几到几,10 ~ 99,soyou will be like them……,输入的数字的范围就是10 <= 输入的数 <= 99 tips:在程序中不能这么写,要用&&,即10 <= 输入的数 && 输入的数 <= 99参考代码
#include <iostream> using namespace std; int main() { int a; cin >> a; if (10 <= a && a <= 99) { cout << 1; } else { cout << 0; } return 0; }
-
-1
1.循环
#include <bits/stdc++.h> using namespace std; int main() { int n, num = 0; cin >> n; while(n > 0) { num++; n /= 10; } if(num == 2) { cout << "1"; return 0; } cout << "0"; return 0; }
2.if判断
#include <iostream> using namespace std; int main() { int n; cin >> n; if(n >= 10 && n <= 99) { cout << 1; } else { cout << 0; } return 0; }
3.字符串
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; if(s.length() == 2) { cout << 1; } else { cout << 0; } return 0; }
信息
- ID
- 148
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 3
- 标签
- 递交数
- 1908
- 已通过
- 1026
- 上传者