标签:++ names std 展开 子串 int 最大 map length
#include <iostream> using namespace std; int main() { int n; while(cin >> n) { if(n == 0 || n %2 == 0) cout << endl; else { for(int i = 0; i < n / 2; i++) { for(int j = 0; j < n; j++) { if(j > n / 2 - i && j < n / 2 + i) cout << " "; else cout << "*"; } cout << endl; } for(int i = n / 2; i < n; i++) { for(int j = 0; j < n; j++) { if(j > i - n / 2 && j < n + n / 2 - i - 1) cout << " "; else cout << "*"; } cout << endl; } } } return 0; }
#include<iostream> #include<vector> using namespace std; vector<string> perm(vector<string> a, vector<string> b) { vector<string> v; for(int i = 0; i < a.size(); i++) { for(int j = 0; j < b.size(); j++) { v.push_back(a[i] + b[j]); } } return v; } int main() { int n, i, j ,k; char ch[3] = {‘a‘, ‘b‘, ‘c‘}; while (cin >> n) { vector<string> v, res; v = {"a", "b", "c"}; res = v; for(i = 1; i < n; i++) { res = perm(res, v); } for(i = 0; i < res.size(); i++) { cout << res[i]; if(i < res.size() - 1) cout << ","; } cout << " " << res.size() << endl; } return 0; }
#include <iostream> #include <vector> #include <stack> using namespace std; int main() { string s; while (cin >> s) { int i, l, j = 0; int st[100]; stack<int> ss; l = s.length(); for (i = 0; i < l; i++) { if (s[i] == ‘(‘) { if (s[i - 1] == ‘-‘) st[j++] = 1; else st[j++] = 0; ss.push(i); } else if (s[i] == ‘)‘) { if (st[--j] == 1) { int k = ss.top(); while (k != i) { if (s[k] == ‘-‘) s[k++] = ‘+‘; else if (s[k] == ‘+‘) s[k++] = ‘-‘; else k++; } } ss.pop(); } else continue; } for (i = 0; i < l; i++) { if (s[i] == ‘(‘ || s[i] == ‘)‘) continue; cout << s[i]; } cout << endl; } return 0; }
#include<iostream> #include<vector> #include<map> using namespace std; int main() { string a, b; while(cin >> a >> b) { int la = a.length(); int lb = b.length(); int maxn = 0, num = 0; map<int, vector<string> > mmp; string str; for(int i = 0; i < la; i++) { for(int j = 0; j < lb; j++) { if(a[i] == b[j]) { int pi = i, pj = j; while(a[pi] == b[pj] && pj < lb && pi < la) { num++; str += a[pi]; pj++; pi++; } if(num >= maxn) maxn = num; mmp[num].push_back(str); str = ""; num = 0; } } } cout << maxn << " " << mmp[maxn].size() << endl; } return 0; }
标签:++ names std 展开 子串 int 最大 map length
原文地址:https://www.cnblogs.com/ache/p/12576237.html