笔试强训(九)
一. 添加逗号
https://www.nowcoder.com/practice/f51c317e745649c0900996fd3f683aed?tpId=290&tqId=39934&ru=/exam/oj



#include<iostream>
#include<algorithm>
using namespace std;int main()
{string s;cin >> s;string str;int count = 0;int n = s.size();for (int i = n - 1; i >= 0; i--){str += s[i];count++;if (count == 3 && i != 0){count = 0;str += ',';}}reverse(str.begin(),str.end());cout << str << endl;return 0;
}
二.跳台阶
https://www.nowcoder.com/practice/bfb2a2b3cdbd4bd6bba0d4dca69aa3f0?tpId=230&tqId=39749&ru=/exam/oj


#include <iostream>
using namespace std;int main()
{int n;cin >> n;int a = 1, b = 1, c;for(int i = 2; i <= n; i++){c = a + b;a = b;b = c;}if(n == 0 || n == 1) cout << n << endl;else cout << c << endl;return 0;
}
三.扑克牌顺子
https://www.nowcoder.com/practice/762836f4d43d43ca9deb273b3de8e1f4?tpId=13&tqId=11198&ru=/exam/oj



#include <iostream>
#include <vector>using namespace std;class Solution {
public:/*** 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可** * @param numbers int整型vector * @return bool布尔型*/bool hash[14] = { 0 };bool IsContinuous(vector<int>& n) {// write code hereint maxval = 0;int minval = 14;for (auto e : n){if (e){if (hash[e]){return false;}hash[e]=1;maxval = max(maxval, e);minval = min(minval, e);}}return maxval - minval <= 4;}
};