本文共 13606 字,大约阅读时间需要 45 分钟。
#include#include using namespace std;int main(){ string str; while (cin>>str) { string res = ""; for (int i = 0; i < str.size(); i++) { if (str[i] >= '0' && str[i] <= '9') { if (i == 0 || str[i - 1] < '0' || str[i - 1] > '9') { res += '*'; } res += str[i]; if (i == str.size() - 1 || (str[i + 1] < '0' || str[i + 1] > '9')) { res += '*'; } } else { res += str[i]; } } cout< <
#includeusing namespace std;int main(){ int n; while (cin>>n) { int cnt = 0; while (n) { ++cnt; n &= n - 1; } cout< <
#include#include #include #include using namespace std;void fun(string pat, string dest){ int patLen = pat.size(); int destLen = dest.size(); vector > dp(patLen + 1, vector (destLen + 1, 0)); dp[0][0] = 1; for (int i = 1; i <= patLen; i++) { for (int j = 1; j <= destLen; j++) { if (pat[i - 1] == '?' || abs(pat[i - 1] - dest[j - 1]) == 0 || abs(pat[i - 1] - dest[j - 1]) == 32) { dp[i][j] = dp[i - 1][j - 1]; } else if (pat[i - 1] == '*') { dp[i][j] = dp[i - 1][j - 1] || dp[i][j - 1] || dp[i - 1][j]; } } } if (dp[patLen][destLen]) { cout<<"true"< >pat>>str) { fun(pat, str); } return 0;}
#includeusing namespace std;int main(){ int n; cin>>n; for (int i = 0; i <= 100 / 5; i++) { for (int j = 0; j <= 100 / 3; j++) { int k = 100 - i - j; if (5 * i + 3 * j + k / 3.0 == 100) { cout< <<" "< <<" "< <
#includeusing namespace std;int main(){ int n; while (cin>>n) { int num = n * n - n + 1; cout<
#include#include #include using namespace std;int fun(string str1, string str2){ int len1 = str1.size(); int len2 = str2.size(); vector > dp(len1 + 1, vector (len2 + 1, 0)); for (int i = 0; i <= len2; i++) { dp[0][i] = i; } for (int i = 0; i <= len1; i++) { dp[i][0] = i; } for (int i = 1; i <= len1; i++) { for (int j = 1; j <= len2; j++) { dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + 1; dp[i][j] = min(dp[i][j], dp[i -1][j - 1] + (str1[i - 1] == str2[j - 1] ? 0 : 1)); } } return dp[len1][len2];}int main(){ string str1, str2; while (cin>>str1>>str2) { int res = fun(str1, str2); cout<<"1/"< <
#includeusing namespace std;int main(){ int n; while (cin>>n) { int cnt = 0; int res = 0; for (int i = 0; i < 8; i++) { if (n & 0x1 << i) { ++cnt; } else { res = max(res, cnt); cnt = 0; } } res = max(res, cnt); cout< <
#include#include using namespace std;//合并表记录int main(){ int n; while (cin>>n) { vector > src(n, vector (2, 0)); for (int i = 0; i < n; i++) { cin>>src[i][0]>>src[i][1]; } vector > dest; for (int i = 0; i < n; i++) { bool b = false; for (int j = 0; j < dest.size(); j++) { if (dest[j][0] == src[i][0]) { dest[j][1] += src[i][1]; b = true; } } if (!b) { dest.push_back(src[i]); } } for (int i = 0; i < dest.size(); i++) { cout< < < <
#include#include using namespace std;int main(){ string str; while (getline(cin, str)) { int len = str.size(); int small = 0; int big = 0; int number = 0; int mark = 0; for (int i = 0; i < len; i++) { if (str[i] >= 'a' && str[i] <= 'z') { small++; } else if (str[i] >= 'A' && str[i] <= 'Z') { big++; } else if (str[i] >= '0' && str[i] <= '9') { number++; } else if ((str[i] >= 0x21 && str[i] <= 0x2F) || (str[i] >= 0x3A && str[i] <= 0x40) || (str[i] >= 0x5B && str[i] <= 0x60) || (str[i] >= 0x7B && str[i] <= 0x7E)) { mark++; } } int score = 0; if (len <= 4) { score += 5; } else if (len <= 7) { score += 10; } else { score += 25; } if (big != 0 && small != 0) { score += 20; } else if (big != 0 || small != 0) { score += 10; } if (number == 1) { score += 10; } else if (number > 1) { score += 20; } if (mark == 1) { score += 10; } else if (mark > 1) { score += 25; } if (score >= 90) { cout<<"VERY_SECURE"< = 80) { cout<<"SECURE"< = 70) { cout<<"VERY_STRONG"< = 60) { cout<<"STRONG"< = 50) { cout<<"AVERAGE"< = 25) { cout<<"WEAK"<
#include#include using namespace std;void fun(vector num, int sum, int pos, bool& stat){ if (pos < 0) { return; } if (num[pos] == sum) { stat = true; } fun(num, sum - num[pos], pos - 1, stat); fun(num, sum, pos - 1, stat);}int main(){ int n; while (cin>>n) { vector num; int sum = 0; int sum3 = 0; int sum5 = 0; int temp; for (int i = 0; i < n; i++) { cin>>temp; sum += temp; if (temp % 5 == 0) { sum5 += temp; } else if (temp % 3 == 0) { sum3 += temp; } else { num.push_back(temp); } } if (sum % 2 != 0 || sum3 > sum / 2 || sum5 > sum / 2) { cout<<"false"<
#include#include using namespace std;int main(){ int can; while (cin>>can) { vector arr(can, 0); vector res(can + 1, 0); for (int i = 0; i < can; i++) { cin>>arr[i]; } int vote; cin>>vote; char ch; for (int i = 0; i < vote; i++) { cin>>ch; bool b = false; for (int j = 0; j < can; j++) { if (arr[j] == ch) { res[j]++; b = true; } } if (!b) { res[can]++; } } for (int i = 0; i < can; i++) { cout< <<" : "< <
#includeusing namespace std;int main(){ int n; while (cin>>n) { cout<<1.5 * n * n + 0.5 * n<
#include#include #include using namespace std;double fun(double d){ if (d < 0) { return -fun(-d); } double left = 0; double right = d; while (left < right) { double mid = (left + right) / 2; if (mid * mid * mid < d - 1e-6) { left = mid; } else if (mid * mid * mid > d + 1e-6) { right = mid; } else { return mid; } } return left;}int main(){ double d; while (cin>>d) { printf("%.1f\n", fun(d)); } return 0;}
#includeusing namespace std;int yue(int n, int m){ if (n < m) { swap(n, m); } int a = n % m; while (a) { n = m; m = a; a = n % m; } return m;}int bei(int n, int m){ return n * m / (yue(n, m));}int main(){ int n, m; while (cin>>n>>m) { cout<
#include#include #include using namespace std;int main(){ int n; while (cin>>n) { vector num(n, 0); for (int i = 0; i < n; i++) { cin>>num[i]; } sort(num.begin(), num.end()); int i = 0; for (int j = 1; j < num.size(); j++) { if (num[j] != num[i]) { num[++i] = num[j]; } } for (int j = 0; j <= i; j++) { cout< <
#include#include using namespace std;int main(){ string str; while (getline(cin, str)) { for (int i = 0, j = str.size() - 1; i < j; i++, j--) { char ch = str[i]; str[i] = str[j]; str[j] = ch; } cout< <
#include#include #include #include #include using namespace std;bool isBrother(string str1, string str2){ if (str1.compare(str2) == 0 || str1.size() != str2.size()) { return false; } int b[26] = { 0}; for (int i = 0; i < str1.size(); i++) { b[str1[i] - 'a']++; } for (int i = 0; i < str2.size(); i++) { b[str2[i] - 'a']--; } for (int i = 0; i < 26; i++) { if (b[i] != 0) { return false; } } return true;}int main(){ int n; while (cin>>n) { vector words(n, ""); for (int i = 0; i < n; i++) { cin>>words[i]; } vector > brothers; for (int i = 0; i < n; i++) { vector bro; for (int j = 0; j < n; j++) { if (j == i) { continue; } if (isBrother(words[i], words[j])) { bro.push_back(j); } } brothers.push_back(bro); } //sort for (int i = 0; i < n; i++) { int len = brothers[i].size(); for (int j = 0; j < len - 1; j++) { for (int k = 0; k < len - 1 - j; k++) { if (words[k].compare(words[k + 1]) > 0) { swap(brothers[i][k], brothers[i][k + 1]); } } } } string str; cin>>str; int index; cin>>index; for (int i = 0; i < n; i++) { if (str.compare(words[i]) == 0) { cout< < <
#include#include #include #include #include using namespace std;bool isPrime(int n){ for (int i = 2; i <= n / 2; i++) { if (n % i == 0) { return false; } } return true;}int main(){ int n; while (cin>>n) { vector num(n , 0); for (int i = 0; i < n; i++) { cin>>num[i]; } vector dp(n + 1, 0); for (int i = 1; i <= n; i++) { for (int j = i + 1; j <= n; j++) { if (isPrime(num[i - 1] + num[j - 1])) { dp[i] = max(dp[i], dp[i - 1] + dp[j - 1] - dp[j] + 1); } else { dp[i] = max(dp[i], dp[i - 1]); } } } cout< <
#include#include #include using namespace std;char map[16] ={ '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};char fun(char ch){ int n; if (ch >= '0' && ch <= '9') { n = ch - '0'; } else if (ch >= 'a' && ch <= 'f') { n = ch - 'a' + 10; } else if (ch >= 'A' && ch <= 'F') { n = ch - 'A' + 10; } n = (n & 1) << 3 | (n & 1 << 1) << 1 | (n & 1 << 2) >> 1 | (n & 1 << 3) >> 3; return map[n];}int main(){ string str1, str2; while (cin>>str1>>str2) { string str = str1 + str2; for (int i = 0; i < str.size() - 1; i++) { for (int j = 0; j < str.size() - 2 - i; j++) { if (str[j] > str[j + 2]) { swap(str[j], str[j + 2]); } } } for (int i = 0; i < str.size(); i++) { if (str[i] >= '0' && str[i] <= '9' || str[i] >= 'a' && str[i] <= 'f' || str[i] >= 'A' && str[i] <= 'F') { str[i] = fun(str[i]); } } cout< <
#includeusing namespace std;int m[12] = { 31,28,31,30,31,30,31,31,30,31,30,31};bool fun(int year){ if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) { return true; } return false;}int main(){ int year, month, day; while (cin>>year>>month>>day) { int sum = 0; for (int i = 0; i < month - 1; i++) { sum += m[i]; } sum += day; if (fun(year) && sum > 59) { sum++; } cout< <
转载地址:http://iglzl.baihongyu.com/