760
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include <cstdio> int main() { char str[100]; scanf("%[^\n]", str); int count = 0; for (int i = 0; str[i] != '\0'; ++i) { count++; } printf("%d\n", count); return 0; } |
761
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include <iostream> #include <cctype> int main() { std::string str; getline(std::cin, str); int count = 0; for (auto ch : str) { if (isdigit(ch)) { count++; } } std::cout << count << std::endl; return 0; } |
763
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <iostream> int main() { int n = 0; std::cin >> n; while(n--) { std::string str1, str2; std::cin >> str1 >> str2; if (str1.compare(str2) == 0) { std::cout << "Tie" << std::endl; } else if ((str1.compare("Hunter") == 0 && str2.compare("Gun") == 0) || (str1.compare("Gun") == 0 && str2.compare("Bear") == 0) || (str1.compare("Bear") == 0 && str2.compare("Hunter") == 0)) { std::cout << "Player1" << std::endl; } else { std::cout << "Player2" << std::endl; } } return 0; } |
765
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include <iostream> int main() { std::string str; getline(std::cin, str); std::string res; for (auto ch : str) { res += ch; res += ' '; } std::cout << res << std::endl; return 0; } |
769
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include <iostream> int main() { std::string str; char ch; getline(std::cin, str); std::cin >> ch; for (size_t i = 0; i < str.size(); ++i) { if (str[i] == ch) { str[i] = '#'; } } std::cout << str << std::endl; return 0; } |
773
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <iostream> int main() { std::string str, substr; while(std::cin >> str >> substr) { int max_index =0; int max_assic = str[0]; for (size_t i = 0; i < str.size(); ++i) { if (str[i] > max_assic) { max_assic = str[i]; max_index = i; } } std::string prefix = str.substr(0, max_index+1); std::string suffix = str.substr(max_index+1, str.size()-max_index); std::string res = prefix + substr + suffix; std::cout << res << std::endl; } return 0; } |
772
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
#include <iostream> int main() { std::string str; std::cin >> str; int arr[26] = {0}; int index[26] = {0}; int count = 0; for (auto ch : str) { if (arr[ch - 'a'] == 0) { index[ch - 'a'] = count; } arr[ch - 'a']++; count++; } char ch; int min_index = 0; bool start = true; for (int i = 0; i < 26; ++i) { if (arr[i] == 1 && start) { min_index = index[i]; start = false; } else if (arr[i] == 1 && !start) { if (min_index > index[i]) { min_index = index[i]; } } } bool flag = true; for (int i = 0; i < 26; ++i) { if (arr[i] == 1) { flag = false; break; } } if (flag) { std::cout << "no" << std::endl; } else { std::cout << str[min_index] << std::endl; } return 0; } |
762
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include <iostream> int main() { double k = 0.0; std::string str1, str2; std::cin >> k >> str1 >> str2; int count = 0; for (int i = 0; i < str1.size(); ++i) { if (str1[i] == str2[i]) { count++; } } double per = count/static_cast<double>(str1.size()); if (per >= k) { std::cout << "yes" << std::endl; } else { std::cout << "no" << std::endl; } return 0; } |
768
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
#include <iostream> #include <algorithm> int main() { std::string str1, str2; getline(std::cin, str1); getline(std::cin, str2); std::transform(str1.begin(), str1.end(), str1.begin(), tolower); std::transform(str2.begin(), str2.end(), str2.begin(), tolower); int res = str1.compare(str2); if (res == 0) { std:: cout << "=" << std::endl; } else if (res < 0) { std:: cout << "<" << std::endl; } else if (res > 0) { std:: cout << ">" << std::endl; } return 0; } |
766
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include <iostream> int main() { std::string str; getline(std::cin, str); std::string res; int j = 0; for (auto ch : str) { if (!isblank(ch)) { if (j != 0) { res += ' '; j = 0; } res += ch; } else { j++; } } std::cout << res << std::endl; return 0; } |
767
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include <iostream> int main() { std::string str; getline(std::cin, str); for (int i = 0; i < str.size(); ++i) { if (islower(str[i])) { str[i] = (str[i] + 1 > 122) ? 97 : str[i]+1; } else if (isupper(str[i])) { str[i] = (str[i] + 1 > 90) ? 65 : str[i]+1; } } std::cout << str << std::endl; return 0; } |
764
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include <iostream> int main() { std::string str; getline(std::cin, str); std::string res; for (int i = 0; i < str.size(); ++i) { char ch; if (i == str.size()-1) { ch = str[i] + str[0]; } else { ch = str[i] + str[i+1]; } res += ch; } std::cout << res << std::endl; return 0; } |
770
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include <iostream> #include <string> int main() { std::string str, str_find, str_rep; getline(std::cin, str); std::cin >> str_find; std::cin >> str_rep; int len = str_find.size(); int start = 0; size_t index = str.find(str_find, start); while (index != std::string::npos) { if ((isblank(str[index-1]) || index == 0) && (isblank(str[index+len]) || (index+len) == str.size())) { str.replace(index, len, str_rep); } start = index + 1; index = str.find(str_find, start); } std::cout << str << std::endl; return 0; } |
771
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
#include <iostream> int main() { int count = 0; std::cin >> count; char ch_his; int num_his = 0; while(count--) { std::string str; std::cin >> str; char ch = str[0]; int num = 0; for (size_t i = 0; i < str.size(); ++i) { if (str[i] == ch) { num++; if (num > num_his) { ch_his = ch; num_his = num; } } else { if (num > num_his) { ch_his = ch; num_his = num; } ch = str[i]; num = 1; } } std::cout << ch_his << " " << num_his << std::endl; num_his = 0; } return 0; } |
774
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#include <iostream> int main() { std::string str; getline(std::cin, str); std::string str_his; int start = 0, len = 0; for (size_t i = 0; i < str.size(); ++i) { if (isblank(str[i]) && i == 0) { start = i + 1; } else if (isblank(str[i]) || str[i] == '.') { std::string temp = str.substr(start, i - start); if (temp.size() > str_his.size()) { str_his = temp; } start = i + 1; } } std::cout << str_his << std::endl; return 0; } |
775
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#include <iostream> #include <vector> int main() { std::string str; getline(std::cin, str); std::vector<std::string> vec; int start = 0; for(size_t i = 0; i < str.size(); ++i) { if (isblank(str[i])) { vec.emplace_back(str.substr(start, i-start)); start = i + 1; i = start; } if (i + 1 == str.size()) { vec.emplace_back(str.substr(start, i-start+1)); } } auto rite = vec.rbegin(); while(rite != vec.rend()) { std::cout << *rite << " "; rite++; } return 0; } |
776
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#include <iostream> #include <string> void move(std::string& str) { std::string res = str; size_t len = res.size(); res = res.substr(1, len-1) + str[0]; str = res; } bool is_find(std::string& str, const std::string str_find) { bool flag = false; for (size_t i = 0; i < str.size(); ++i) { move(str); if (str.find(str_find, 0) != std::string::npos) { flag = true; break; } } return flag; } int main() { std::string str1, str2; std::cin >> str1 >> str2; if (is_find(str1, str2) || is_find(str2, str1)) { std::cout << "true" << std::endl; } else { std::cout << "false" << std::endl; } return 0; } |
777
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
#include <iostream> #include <vector> std::string get_find(const std::string str) { std::string res; std::vector<int> vec; for (size_t i = 1; i <= str.size(); ++i) { if (str.size() %i == 0) { vec.emplace_back(i); } } int max = vec[0]; for (auto item : vec) { int len = str.size()/item; std::string temp = str.substr(0, len); std::string temp_res; for (int i = 0; i < item; ++i) { temp_res += temp; } if (temp_res.size() > str.size()) { continue; } if (temp_res.compare(str) == 0) { if (max < item) { max = item; } } } res = str.substr(0, str.size()/max); return res; } int main() { std::string str; while(std::cin >> str, str.compare(".") != 0) { std::string find = get_find(str); int res = str.size()/find.size(); std::cout << res << std::endl; } return 0; } |
778
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
#include <iostream> #include <vector> #include <string> int main() { std::string str, str1, str2, str3; std::cin >> str; int start = 0; int index = str.find(",", start); str1 = str.substr(start, index-start); start = index + 1; index = str.find(",", start); str2 = str.substr(start, index-start); start = index + 1; str3 = str.substr(start, str.size()-start); std::vector<int> vec1; start = 0; size_t pos = str1.find(str2, start); while (pos != std::string::npos) { vec1.emplace_back(pos); start = pos + 1; pos = str1.find(str2, start); } start = 0; std::vector<int> vec2; pos = str1.find(str3, start); while (pos != std::string::npos) { vec2.emplace_back(pos); start = pos + 1; pos = str1.find(str3, start); } if (vec1.size() == 0 || vec2.size() == 0) { std::cout << -1 << std::endl; } else { int index1 = vec1[0]+str2.size(); int index2 = vec2[vec2.size()-1]; int x = index2 - index1; if (x >= 0) { std::cout << x << std::endl; } else { std::cout << -1 << std::endl; } } return 0; } |
779
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#include <iostream> #include <vector> int main() { int n = 0; while (std::cin >> n, n > 0) { std::vector<std::string> vec; std::string str; while (n--) { std::cin >> str; vec.emplace_back(str); } size_t min_size = vec[0].size(); std::string str_start = vec[0]; for (auto item : vec) { if (item.size() < min_size) { min_size = item.size(); str_start = item; } } int count = 0; int start = 0; char ch = str_start[str_start.size() - 1]; for (size_t i = 0; i < min_size; ++i) { bool flag = true; for (auto str : vec) { if (str[str.size() - 1 - start] != ch) { flag = false; break; } } if (flag) { count++; start++; int s = str_start.size(); if (s - 1 - start >= 0) { ch = str_start[s - 1 - start]; } } else { break; } } std::cout << str_start.substr(str_start.size() - count, count) << std::endl; } return 0; } |
本文为原创文章,版权归Aet所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ 【AcWing 语法基础课 第四讲】02/23
- ♥ 【AcWing 语法基础课 第二讲】02/17
- ♥ 【LeetCode-Apr-链表二】04/02
- ♥ 【AcWing 语法基础课 第三讲】02/22
- ♥ 【LeetCode-April】04/02
- ♥ 【AcWing 语法基础课 第一讲】02/14