AK代码。还行。
#include <bits/stdc++.h> using namespace std; int main(){ int n; while(cin >> n) { int cnt = 0; while(n) { cnt += n/5; n /= 5; } cout << cnt << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; while (cin >> s) { unordered_map<long long, unordered_set<long long>> vis; long long x = 0, y = 0; bool find = false; vis[0].insert(0); for (int i = 0; i < s.size(); i++) { if (s[i] == 'E') { x += 1; } else if (s[i] == 'W') { x -= 1; } else if (s[i] == 'N') { y += 1; } else if(s[i] == 'S'){ y -= 1; } if (vis.find(x) != vis.end() && vis[x].find(y) != vis[x].end()) { find = true; break; } vis[x].insert(y); } if (find) { cout << "True" << endl; } else { cout << "False" << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; bool pairChar(char a, char b) { if(a == '(' && b == ')') return true; if(a == '{' && b == '}') return true; if(a == '[' && b == ']') return true; return false; } int main() { string s; while(cin >> s) { stack<char> stack; bool valid = true; for(int i = 0; i < s.size(); i++) { if(s[i] == '(' || s[i] == '{' || s[i] == '[') { stack.push(s[i]); } else { if(!stack.empty() && pairChar(stack.top(), s[i])) { stack.pop(); } else { valid = false; break; } } } if(!valid || !stack.empty()) { cout << "False" << endl; } else { cout << "True" << endl; } } return 0; }
全部评论
(0) 回帖