text
stringlengths
1
24.5M
#include <iostream> #include <algorithm> using namespace std; int main(){ int first, n, k, temp; cin >> first >> n >> k; int data[100000], next[100000], list[100000]; for(int i = 0; i < n; i++){ cin >> temp; cin >> data[temp] >> next[temp]; } int sum = 0; while(first != -1){ list[sum++] = first; first = ...
#include <iostream> using namespace std; int main() { int a, b; cin >> a >> b; int n = ((b - a) + 50) / 100; //+50 是为了处ç†å››èˆäº”å…¥ int hour = n / 3600; n = n % 3600; int minute = n / 60, second = n % 60; printf("%02d:%02d:%02d", hour, minute, second); return 0; }
#include <iostream> #include <cmath> using namespace std; int main(){ int N, n, t; cin >> N; char c; cin >> c; n = sqrt((N + 1) / 2); t = N - 2 * n * n + 1; for(int i = n; i >= 1; i--){ for(int j = 0; j < (2 * n - (2 * i - 1)) / 2; j++) cout << " "; for(int k = 0; k < 2 * i - 1; k++) cout << c; cout << en...
#include <iostream> using namespace std; int main() { int N, row = 0; char c; cin >> N >> c; for (int i = 0; i < N; i++) { if ((2 * i * (i + 2) + 1) > N) { row = i - 1; break; } } for (int i = row; i >= 1; i--) { for (int k = row - i; k >= 1; k--) ...
#include <iostream> using namespace std; int main(){ int n; cin >> n; string name; int year, month, day, count = 0; int maxyear = 0, maxmonth = 0, maxday = 0, minyear = 9999, minmonth = 9999, minday = 9999; string maxname, minname; for(int i = 0; i < n; i++){ cin >> name; scanf("%d/%d/%d", &year, &month, &d...
#include <iostream> #include <string> using namespace std; int main(){ string s1, s2, ans; int pos; cin >> s1 >> s2; for (int i = 0; i < s1.length(); i++) if(s2.find(s1[i]) == string::npos && ans.find(toupper(s1[i])) == string::npos) // a中包å«bæ—¶ a.find(b) != string::npos ans += toupper(s1[i]); cout <<...
#include <iostream> #include <algorithm> #include <vector> using namespace std; int main(){ int n; long long p; cin >> n >> p; vector<int> v(n); for(int i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end()); int result = 0, temp = 0; for(int i = 0; i < n; i++){ for(int j = i + result; j < n; j++){ if(...
#include <iostream> #include <string> using namespace std; int main() { int N; string s; int wight[17] = {7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2}; char M[11] = {'1','0','X','9','8','7','6','5','4','3','2'}; cin >> N; int sum, count = 0, is_false; for(int i = 0; i < N; i++){ cin >> s; sum = 0; is_false = 0; ...
#include <iostream> #include <vector> using namespace std; int main(){ int N, num, score, sum; cin >> N; vector<int> v(N + 1); for(int i = 0; i < N; i++){ cin >> num >> score; v[num] += score; } int max = v[1], t = 1; for(int i = 2; i <= N; i++){ if(max < v[i]){ max = v[i]; t = i; } } cout << t <...
#include <iostream> #include <cctype> using namespace std; int main() { string bad, should; getline(cin, bad); //为了防止第一行是空的,ä¸èƒ½ç”¨cin >> ,用getline(cin, ...) getline(cin, should); for (int i = 0, length = should.length(); i < length; i++) { if (bad.find(toupper(should[i])) != strin...
#include <iostream> #include <cmath> using namespace std; long long a, b, c, d; long long gcd(long long t1, long long t2) { return t2 == 0 ? t1 : gcd(t2, t1 % t2); } void func(long long m, long long n) { int flag1 = 0, flag2 = 0, flag = 0; if (n == 0) { printf("Inf"); return ; } if (...
#include <iostream> #include <algorithm> using namespace std; int main() { int n; cin >> n; int *a = new int [n]; int *b = new int [n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; int i, j; for (i = 0; i < n - 1 && b[i] <= b[i + 1]; i...
#include <iostream> using namespace std; int main(){ int N, count; char c; cin >> N >> c; count = N / 2 + N % 2; for(int i = 0; i < count; i++){ if(i == 0 || i == count - 1){ for(int j = 0; j < N; j++) cout << c; cout << endl; }else{ for(int j = 0; j < N; j++){ if(j == 0 || j == N - 1) ...
#include <iostream> using namespace std; int main(){ int G, S, K, G1, S1, K1, sum; scanf("%d.%d.%d %d.%d.%d.",&G,&S,&K,&G1,&S1,&K1); sum = (K1 + S1 * 29 + G1 * 17 * 29) - (K + S * 29 + G * 17 * 29); if (sum < 0){ cout << "-"; sum = -1 * sum; } G = sum / 17 / 29; sum -= G * 17 * 29; S = sum / 29; sum -= S *...
#include <iostream> #include <vector> using namespace std; int main(){ int n, m, temp; cin >> n; vector<int> b(101); for(int i = 0; i < n; i++){ scanf("%d", &temp); // cin比scanf慢 b[temp]++; } cin >> m; for(int i = 0; i < m; i++){ scanf("%d", &temp); if(i != 0) printf(" "); printf("%d",b[temp]); }...
#include <iostream> using namespace std; int main(){ string a, b; cin >> a >> b; for(int i = 0; i < b.length(); i++){ for(int j = 0; j < a.length(); j++){ if(a[j] == b[i]){ b[i] = '#'; a[j] = '#'; } } } int cnt1 = 0, cnt2 = 0; for(int i = 0; i < b.length(); i++) if(b[i] != '#') cnt1++; for(in...
#include <iostream> #include <string> using namespace std; int main(){ string s; cin >> s; int len = s.length(), result = 0, countp = 0, countt = 0; for(int i = 0; i < len; i++){ if(s[i] == 'T') countt++; } for(int i = 0; i < len; i++){ if(s[i] == 'P') countp++; if(s[i] == 'T') countt--; if(s[i] == 'A') r...
#include <iostream> #include <vector> using namespace std; int main(){ int n, N, t_num, temp; string num, s_num; cin >> N; vector<string> v(N+1); for(int i = 1; i <= N; i++){ cin >> num >> t_num >> s_num; v[t_num] = num + " " + s_num; } cin >> n; for(int i = 0; i < n; i++){ cin >> temp; cout << v[temp] ...
#include <iostream> #include <cctype> #include <string> using namespace std; int main(){ string s; getline(cin, s); int a[26] = {0}; for(int i = 0; i < s.length(); i++) s[i] = tolower(s[i]); for(int i = 0; i < s.length(); i++) if(islower(s[i])) a[s[i] - 'a']++; int max = a[0], t = 0; for(int i = 1; i < 26; i...
#include <iostream> using namespace std; int main() { int map[128] = {0}, c; while ((c = cin.get()) != EOF) map[c]++; while (map['P'] > 0 || map['A'] > 0 || map['T'] > 0 || map['e'] > 0 || map['s'] > 0 || map['t'] > 0) { if (map['P']-- > 0) cout << 'P'; if (map['A']-- > 0) cout << 'A'; if (map['T']-- ...
#include <iostream> #include <string> using namespace std; void func1(string s){ //toç«æ˜Ÿæ–‡ string a[13] = {"###", "jan", "feb", "mar", "apr", "may", "jun", "jly", "aug", "sep", "oct", "nov", "dec"}; string b[13] = {"###", "tam", "hel", "maa", "huh", "tou", "kes", "hei", "elo", "syy", "lok", "mer", "jou"}; int ...
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ int n, temp, max = 0, tmp = 0; scanf("%d", &n); //使用cin,cout会慢很多,就这个题,用cin,cout 是114ms, 用scanf,printf是41ms. vector<int> a(n), b(n), v(n); for(int i = 0; i < n; i++){ scanf...
#include <iostream> using namespace std; int main(){ int n, jia_a, jia_b, yi_a, yi_b, jia_count = 0, yi_count = 0; cin >> n; for(int i = 0; i < n; i++){ cin >> jia_a >> jia_b >> yi_a >> yi_b; if(jia_b == jia_a + yi_a && jia_b != yi_b) yi_count++; if(yi_b == jia_a + yi_a && yi_b != jia_b) jia_count++; } cout ...
#include <iostream> using namespace std; int main(){ int n, temp, num_a, num_b, max_num, max = 0; cin >> n; int team[1001] = {0}; //ç”¨åŠ¨æ€æ•°ç»„ä¼šå¾ˆæ…¢ï¼Œé™æ€æ•°ç»„虽然浪费空间但会很快 for(int i = 0; i < n; i++){ scanf("%d-%d%d",&num_a, &num_b, &temp); //è¦çµæ´»è¿ç”¨ scanf ,...
#include <iostream> using namespace std; string reverse(string s){ int len = s.length(); for(int i = 0; i <= len / 2 - 1; i++) swap(s[i], s[len - 1 - i]); return s; } int main(){ string a, b, c; cin >> a >> b; a = reverse(a); b = reverse(b); if(a.length() > b.length()) b.append(a.length() - b.length(), '0')...
#include <iostream> using namespace std; int main() { int n; cin >> n; double a[100001]; double sum = 0.0; for (int i = 1; i <= n; i++) { cin >> a[i]; sum = sum + a[i] * i * (n - i + 1); } printf("%.2f", sum); return 0; }
#include <iostream> #include <vector> #include <cmath> #include <algorithm> using namespace std; int func(int N){ int i = sqrt((double)N); while(i >= 1){ if(N % i == 0) return i; i--; } return 1; } int cmp(int a, int b){ return a > b; } int main(){ int N, m, n, t = 0; cin >> N; n = func(N); m = N / n; ...
#include <iostream> #include <cmath> using namespace std; int main(){ double r1, p1, r2, p2, A, B; cin >> r1 >> p1 >> r2 >> p2; A = r1 * r2 * cos(p1) * cos(p2) - r1 * r2 * sin(p1) * sin(p2); B = r1 * r2 * cos(p1) * sin(p2) + r1 * r2 * sin(p1) * cos(p2); if( A + 0.005 >= 0 && A < 0) printf("0.00"); else printf...
#include <iostream> #include <vector> using namespace std; int main (){ vector<vector<string> > v; for(int i = 0; i < 3; i++){ string s; getline(cin, s); vector<string> row; int j = 0, k = 0; while(j < s.length()){ if(s[j] == '['){ while(k++ < s.length()){ if(s[k] == ']'){ row.push_back(s....
#include <iostream> using namespace std; int main(){ int n, d; float e, temp, may = 0, must = 0; cin >> n >> e >> d; for(int i = 0; i < n; i++){ int k, sum = 0; cin >> k; for(int i = 0; i < k; i++){ cin >> temp; if(temp < e) sum++; } if(k > d && sum * 2 > k) must++; else if(sum * 2 > k) may++; } ...
#include <iostream> #include <cstdio> #include <string.h> using namespace std; int main() { int n, cnt = 0; char a[50], b[50]; double temp, sum = 0.0; cin >> n; for(int i = 0; i < n; i++) { scanf("%s", a); sscanf(a, "%lf", &temp); sprintf(b, "%.2lf",temp); int flag = ...
#include <iostream> #include <algorithm> #include <vector> using namespace std; struct node{ string name; int height; }; int cmp(node a, node b){ return a.height != b.height ? a.height > b.height : a.name < b.name; } int main(){ int n, k, m; cin >> n >> k; vector<node> stu(n); for(int i = 0; i < n; i++){ cin >...
#include <iostream> #include <vector> using namespace std; int main(){ int n, temp, sum = 0; cin >> n; vector<int> v(n); for(int i = 0; i < n; i++){ cin >> temp; v[i] = temp; } for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ if(i != j) sum += v[i] * 10 + v[j]; } } cout << sum; return 0; }
#include <iostream> #include <string> using namespace std; int main(){ string s; getline(cin, s); int sum = 0; for(int i = 0; i < s.length(); i++){ if(isalpha(s[i])) sum += tolower(s[i]) - 'a' +1; } int cnt0 = 0, cnt1 = 0; while(sum != 0){ if(sum % 2 == 0) cnt0++; else cnt1++; sum /= 2; } cout...
#include <iostream> #include <cstdio> #include <vector> #include <set> using namespace std; int main(){ int n, m, temp, k; scanf("%d%d", &n, &m); vector<set<char>> right(m); vector<int> total(m), wrongCnt(m); for(int i = 0; i < m; i++){ scanf("%d%d%d", &total[i], &temp, &k); for(int j = 0; j < k; j++){ char...
#include <iostream> #include <set> #include <cmath> using namespace std; int ran[10000]; bool isprime(int a) { if(a <= 1) return false; int Sqrt = sqrt((double)a); for(int i = 2; i <= Sqrt; i++) { if(a % i == 0) return false; } return true; } int main() { int n, k; scanf(...
#include <iostream> #include <vector> #include <algorithm> using namespace std; bool cmp(int a, int b){ return a > b; } int main(){ int n; scanf("%d", &n); vector<int> v(n + 1); for(int i = 1; i <= n; ++i){ scanf("%d", &v[i]); } sort(v.begin() + 1, v.end(), cmp); int e = 0, i = ...
#include <iostream> #include <vector> using namespace std; int main(){ int n, m , temp, sum; cin >> n >> m; vector<int> a(m); vector<int> b(m); for(int i = 0; i < m; i++){ cin >> temp; a[i] = temp; } for(int i = 0; i < m; i++){ cin >> temp; b[i] = temp; } for(int i = 0; i < n; i++){ sum = 0; for(in...
#include <iostream> using namespace std; int gcd(int a, int b){ return b == 0 ? a : gcd(b, a % b); } int main() { int n1, m1, n2, m2, k; scanf("%d/%d %d/%d %d", &n1, &m1, &n2, &m2, &k); if(n1 * m2 > n2 * m1){ swap(n1, n2); swap(m1, m2); } int num = 1; bool flag = false; while(n1 * k >= m1 * num) num++; ...
#include <iostream> #include <cmath> using namespace std; int main(){ int n, a, b; float max = 0.0; cin >> n; for(int i = 0; i < n; i++){ cin >> a >> b; float temp = sqrt(a * a + b * b); if(temp > max) max = temp; } printf("%.2f", max); return 0; }
#include <iostream> #include <set> using namespace std; int getFriendNum(int num) { int sum = 0; while(num != 0) { sum += num % 10; num /= 10; } return sum; } int main() { set<int> s; int n, num; cin >> n; for(int i = 0; i < n; i++) { cin >> num; s.insert(...
#include <iostream> #include <vector> #include <set> using namespace std; int main(){ int n, a, b, m; cin >> n; vector<int> v(100000, -1); // ä¸èƒ½è®¾0,因为00000 == 0 for(int i = 0; i < n; i++){ cin >> a >> b; v[a] = b; v[b] = a; } cin >> m; vector<int> g(m), isExist(100000); for(int i = 0; i < m; i+...
#include <iostream> using namespace std; int main(){ int m, n, a, b, r, temp; scanf("%d%d%d%d%d", &m, &n, &a, &b, &r); for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ scanf("%d", &temp); if(temp >= a && temp <= b) printf("%03d",r); else printf("%03d", temp); if(j != n - 1) printf(" "); ...
#include <iostream> using namespace std; int main(){ string pw, temp; int n, cnt = 0; cin >> pw >> n; getchar(); while(1){ getline(cin, temp); if(temp == "#") break; cnt++; if(cnt <= n && temp == pw){ cout << "Welcome in"; break; }else if(cnt <= n && temp != pw){ cout << "Wrong password: " << te...
#include <iostream> #include <vector> #include <map> using namespace std; int m, n, tol; vector<vector<int>> v; int dir[8][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}}; bool judge(int i, int j) { for (int k = 0; k < 8; k++) { int tx = i + dir[k][0]; int ty = j + dir[k]...
#include <iostream> #include <map> using namespace std; int main() { int m, n, s; scanf("%d%d%d", &m, &n, &s); string str; map<string, int> mapp; bool flag = false; for (int i = 1; i <= m; i++) { cin >> str; if (mapp[str] == 1) s = s + 1; if (i == s && mapp[str] == 0) { ...
#include <iostream> #include <algorithm> #include <vector> using namespace std; int main() { int n; scanf("%d", &n); vector<int> v(n); for (int i = 0; i < n; i++) scanf("%d", &v[i]); sort(v.begin(), v.end()); int result = v[0]; for (int i = 1; i < n; i++) result = (result + v...
#include <iostream> using namespace std; int main(){ int T, k, n1, b, t, n2; cin >> T >> k; int sum = T; for(int i = 0; i < k; i++){ cin >> n1 >> b >> t >> n2; if(sum == 0){ cout << "Game Over."; return 0; } else if(t <= sum){ if((b == 0 && n1 > n2) || (b == 1 && n1 < n2)){ sum += t; printf...
#include <iostream> #include <string> using namespace std; bool isExist(string s, string v[], int len){ for(int i = 0; i < len; i++){ if(v[i] == s) return true; } return false; } int main(){ int n, m, num = 0, total = 0; cin >> n >> m; string v[10]; for(int i = 0; i < m; i++) cin >> v[i]; for(int i = 0; i <...
#include <iostream> #include <vector> #include <cmath> using namespace std; int main() { int n = 0, m = 0, opt_num = 0, true_opt_num = 0, temp = 0, max_error_cnt = 0; int hash[] = {1, 2, 4, 8, 16}, opt[1010][110] = {0}; char c; scanf("%d %d", &n, &m); vector<int> full_score(m), true_opt(m); vect...
#include <iostream> using namespace std; int main(){ string s, s1, s2, result; cin >> s >> s1 >> s2; result = s; int carry = 0, flag = 0; string ss1(s.length() - s1.length(), '0'); s1 = ss1 + s1; string ss2(s.length() - s2.length(), '0'); s2 = ss2 + s2; for(int i = s.length() - 1; i >= 0; i--){ int mod = s[i...
#include <iostream> #include <vector> using namespace std; struct node { int data, next; }list[100000]; vector<int> v[3]; int main() { int start, n, k, a; scanf("%d%d%d", &start, &n, &k); for (int i = 0; i < n; i++) { scanf("%d", &a); scanf("%d%d", &list[a].data, &list[a].next); } ...
#include <iostream> using namespace std; int main() { string s; while (cin >> s) if(s.size() == 3 && s[2] == 'T') cout << s[0]-'A'+1; return 0; }
#include <iostream> using namespace std; int main(){ int n, m, t, s; cin >> n >> m; for(int i = 0; i < n; i++){ cin >> t; int sum = 0, max = -1, min = m + 1, num = 0; for(int j = 1; j < n; j++){ cin >> s; if(s >= 0 && s <= m){ sum += s; num++; if(s > max) max = s; if(s < min) min = s; ...
#include <iostream> using namespace std; int main(){ char t; cin >> t; getchar(); string s, num; getline(cin, s); int cnt = 1; if(t == 'D'){ for(int i = 0; i < s.length(); i++){ if(s[i] >= '0' && s[i] <= '9'){ num += s[i]; }else{ if(num.length() > 0) cnt = stoi(num); while(cnt--) cout << s[i]...
#include <iostream> #include <string> #include <algorithm> using namespace std; bool isPal(string s){ for(int i = 0; i < s.length() / 2; i++){ if(s[i] != s[s.length() - i - 1]) return false; } return true; } string add(string a, string b){ string result; int num = 0, carry = 0; for(int i = 0; i < a.length();...
#include <iostream> #include <algorithm> #include <vector> #include <map> using namespace std; struct node{ string name; int gp, gm, gf, g; }; bool cmp(node a, node b){ return a.g != b.g ? a.g > b.g : a.name < b.name; } map<string, int> idx; int main(){ int p, m, n, score, cnt = 1; cin >> p >> m >> n; vector<node...
#include <iostream> #include <cctype> using namespace std; int main() { int n; cin >> n; getchar(); for (int i = 0; i < n; i++) { string s; getline(cin, s); if (s.length() >= 6) { int invalid = 0, hasAlpha = 0, hasNum = 0; for (int j = 0; j < s.length(); j++) ...
#include <iostream> #include <vector> #include <algorithm> using namespace std; struct score{ int id; int num; }; bool cmp(score a, score b){ return a.num < b.num; } int main(){ int n, id, x, y; cin >> n; vector<score> v(n); for(int i = 0 ; i < n; i++){ cin >> id >> x >> y; v[i].id = id; v[i].num = x * x +...
#include <iostream> using namespace std; int main() { int n, t, a[10000] = {0}; cin >> n; for (int i = 1; i <= n; i++) { cin >> t; a[abs(t-i)]++; } for (int i = 9999; i >= 0; i--) if (a[i] >= 2) cout << i << " " << a[i] << endl; return 0; }
#include <iostream> using namespace std; int main(){ string s; int n, j; cin >> s >> n; for(int cnt = 1; cnt < n; cnt++){ string t; for(int i = 0; i < s.length(); i = j){ for(j = i; j < s.length() && s[j] == s[i]; j++); t += to_string((s[i] - '0') * 10 + j - i); } s = t; } cout << s; return 0; }
#include <iostream> #include <algorithm> #include <cctype> #include <vector> #include <unordered_map> using namespace std; struct node { string school; int tws, ns; }; bool cmp(node a, node b) { if (a.tws != b.tws) return a.tws > b.tws; else if (a.ns != b.ns) return a.ns < b.ns; else...
#include <iostream> #include <string> #include <algorithm> using namespace std; int main(){ int a, b; cin >> a >> b; string result = to_string(a * b); reverse(result.begin(), result.end()); cout << stoi(result); //最åŽè¾“出int , string ä¸è¡Œ return 0; }
#include <iostream> #include <set> using namespace std; int main(){ int n; scanf("%d", &n); set<int> v; for(int i = 1; i <= n; i++) v.insert(i / 2 + i / 3 + i / 5); printf("%d", v.size()); return 0; }
#include <iostream> #include <cmath> using namespace std; int m, x, y; void print(double t){ if(m == t) printf(" Ping"); else if(m < t) printf(" Cong"); else printf(" Gai"); } int main(){ scanf("%d %d %d", &m, &x, &y); for(int i = 99; i >= 10; i--){ int j = i % 10 * 10 + i / 10; double k = abs(j - i) * 1.0 / ...
#include <iostream> #include <cmath> #include <vector> using namespace std; int main(){ //有两个狼人,一个狼人说谎,一个好人说谎 int n; cin >> n; vector<int> v(n+1); for(int i = 1; i <= n; i++) cin >> v[i]; for(int i = 1; i <= n; i++){ for(int j = i + 1; j <= n; j++){ vector<int> lie, a(n ...
#include <iostream> #include <vector> #include <map> using namespace std; int main(){ int n, m, t1, t2; map<int, vector<int>> v; scanf("%d%d",&n,&m); for(int i = 0; i < n; i++){ scanf("%d%d",&t1,&t2); v[t1].push_back(t2); v[t2].push_back(t1); } while(m--){ int cnt, flag = 0, a[100000] = {0}; scanf("%d",...
#include <iostream> using namespace std; int main(){ int n; scanf("%d", &n); for(int i = 0; i < n; i++){ int tmp; cin >> tmp; for(int j = 1; j < 10; j++){ string temp = to_string(j * tmp * tmp); string s = to_string(tmp); int len = s.length(); if(s == temp.substr(temp.length() - len, len)){ pri...
#include <iostream> using namespace std; int main(){ int n, m, tmp, max = 0, v[1000] = {0}; scanf("%d%d",&n, &m); // n == 5, m == 3 for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ scanf("%d", &tmp); v[j] += tmp; if(v[j] > max) max = v[j]; } } printf("%d\n", max); int flag = 0; for(int i = 0...
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ string s, result; vector<char> v; for(int i = 0; i < 2; i++){ getline(cin, s); for(int j = 0; j < s.length(); j++){ vector<char>::iterator iter=find(v.begin(), v.end(), s[j]); if(iter == v.end()){ v.push_back(s[...
#include <iostream> #include <cmath> using namespace std; bool isPrime(string s){ int a = stoi(s); if(a < 2) return false; for(int i = 2; i <= sqrt(a); i++){ if(a % i == 0) return false; } return true; } int main(){ int l, k; scanf("%d%d", &l, &k); string s; cin >> s; int flag = 0; for(int i = 0; i < l -...
//#include <bits/stdc++.h> //using namespace std; // //const int maxn = 1e5 + 10; // //struct Node{ // char id[55]; // int score; //}node[maxn], s1[maxn], s2[maxn]; // //Node asd; // //struct N3{ // int room; // int ren; //}num[maxn], endd[maxn]; // //bool cmpp(const N3& a, const N3& b) { // if(a.ren != ...
Position BinarySearch( List L, ElementType X ){ int p = 0; int s = 1; int e = L->Last; int num = e/2; while(num--){ int mid = (s + e) / 2; if(L->Data[mid] == X){ p = mid; break; }else if(L->Data[mid] > X){ e = mid - 1; }else if(L->D...
List Merge( List L1, List L2 ){ List L, p1, p2, tail; L = (List)malloc(sizeof(PtrToNode)); p1 = L1 -> Next; p2 = L2 -> Next; tail = L; while(p1 && p2){ if(p1 -> Data < p2 -> Data){ tail -> Next = p1; tail = p1; p1 = p1 -> Next; L1 -> Next = NULL; L2 -> Next = NULL; }else{ tail -> Next = p2; ...
#include <iostream> using namespace std; int main(){ int k, sum = 0, maxSum = 0; cin >> k; for(int i = 0; i < k; i++){ int temp; cin >> temp; sum += temp; if(sum < 0) sum = 0; if(sum > maxSum) maxSum = sum; } cout << maxSum; return 0; }
#include <iostream> #include <vector> using namespace std; int main() { int n; scanf("%d", &n); vector<int> v(n); int leftindex = 0, rightindex = n - 1, sum = -1, temp = 0, tempindex = 0; for (int i = 0; i < n; i++) { scanf("%d", &v[i]); temp = temp + v[i]; if (temp < 0) { ...
#include <iostream> typedef int element; typedef struct Node { element coef; element exp; struct Node *Next; }node; using namespace std; node *Read(); node *Add(node *L1, node *L2); node *Mult(node *L1, node *L2); void Print(node *L); node *Insert(node *p, element c, element e); int main() { node *L1, *L2, *L3, ...
#include <iostream> #include <algorithm> using namespace std; int main(){ int first, n, k, temp; cin >> first >> n >> k; int data[100000], next[100000], list[100000]; for(int i = 0; i < n; i++){ cin >> temp; cin >> data[temp] >> next[temp]; } int sum = 0; while(first != -1){ list[sum++] = first; first =...
#include <iostream> #include <stack> #include <vector> using namespace std; int main(){ int m, n, k; scanf("%d %d %d", &m, &n, &k); for(int i = 0; i < k; i++){ bool flag = false; stack<int> s; vector<int> v(n + 1); for(int j = 1; j <= n; j++) scanf("%d", &v[j]); int current = 1; for(int j = 1; j <= n...
#include <iostream> #include <algorithm> using namespace std; int main() { int n; cin >> n; int *a = new int [n]; int *b = new int [n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; int i, j; for (i = 0; i < n - 1 && b[i] <= b[i + 1]; i...
#pragma once #include "global.hpppp" #include "scores.hpppp" #include "statistics.hpppp" #include <chrono> #include <cstdint> #include <cstdlib> #include <ctime> #include <iomanip> #include <iostream> #include <limits> #include <math.hpp> #include <string> #include <vector> enum Directions { UP, DOWN, RIGHT, LEFT }; ...
#include "2048.hpp" #include "menu.hpp" int main() { Menu::startMenu(); return 0; }
#include "game-graphics.hpp" #include "color.hpp" #include "global.hpp" #include <array> #include <iomanip> #include <sstream> namespace Game { namespace Graphics { std::string AsciiArt2048() { constexpr auto title_card_2048 = R"( /\\\\\\\\\ /\\\\\\\ /\\\ /\\\\\\\\\ /\\\///////\\...
#include "game-input.hpp" #include "global.hpp" namespace Game { namespace Input { bool check_input_ansi(char c, intendedmove_t &intendedmove) { using namespace Keypress::Code; if (c == CODE_ANSI_TRIGGER_1) { getKeypressDownInput(c); if (c == CODE_ANSI_TRIGGER_2) { getKeypressDownInput(c); swit...
#include "game-pregamemenu.hpp" #include "game-graphics.hpp" #include "game-input.hpp" #include "game.hpp" #include "gameboard.hpp" #include "global.hpp" #include "loadresource.hpp" #include "menu.hpp" #include <array> #include <iostream> #include <limits> #include <sstream> namespace Game { namespace PreGameSetup { ...
#include "game.hpp" #include "game-graphics.hpp" #include "game-input.hpp" #include "game-pregamemenu.hpp" #include "gameboard-graphics.hpp" #include "gameboard.hpp" #include "global.hpp" #include "loadresource.hpp" #include "menu.hpp" #include "saveresource.hpp" #include "scores.hpp" #include "statistics.hpp" #include...
#include "gameboard-graphics.hpp" #include "gameboard.hpp" #include "point2d.hpp" #include "tile-graphics.hpp" #include "tile.hpp" #include <algorithm> #include <array> #include <sstream> namespace Game { namespace Gameboard { namespace Graphics { namespace { template<size_t num_of_bars> std::array<std::string, num_o...
#include "gameboard.hpp" #include "gameboard-graphics.hpp" #include "point2d.hpp" #include <algorithm> #include <array> #include <chrono> #include <random> #include <sstream> #include <utility> namespace Game { namespace { class RandInt { public: using clock = std::chrono::system_clock; RandInt() : dist{0, std::...
#include "global.hpp" #include "color.hpp" #include <iostream> #include <sstream> #ifdef _WIN32 void getKeypressDownInput(char &c) { std::cin >> c; } #else # include <termios.h> # include <unistd.h> char getch() { char buf = 0; struct termios old = {0}; if (tcgetattr(0, &old) < 0) perror("tcsetattr()"...
#include "loadresource.hpp" #include "gameboard.hpp" #include "global.hpp" #include <algorithm> #include <array> #include <fstream> #include <iostream> #include <sstream> #include <string> #include <tuple> #include <vector> namespace Game { namespace Loader { namespace { /** * @brief Counts the number of lines in a ...
#include "menu-graphics.hpp" #include "color.hpp" #include "global.hpp" #include <sstream> namespace Game { namespace Graphics { namespace Menu { std::string MainMenuTitlePrompt() { constexpr auto greetings_text = "Welcome to "; constexpr auto gamename_text = "2048!"; constexpr auto sp = " "; std::ostringst...
#include "menu.hpp" #include "color.hpp" #include "game-graphics.hpp" #include "game.hpp" #include "gameboard.hpp" // To iterate over all saved Games #include "global.hpp" #include "menu-graphics.hpp" #include "scores-graphics.hpp" #include "scores.hpp" #include "statistics-graphics.hpp" #include "statistics.hpp" #incl...
#include "saveresource.hpp" #include "gameboard.hpp" #include <fstream> #include <filesystem> namespace Game { namespace Saver { namespace { /** * @brief Generates a file from the previous game's statistics data. * * This function writes the score and move count of the given game board to the provided output str...
#include "scores-graphics.hpp" #include "color.hpp" #include <array> #include <iomanip> #include <sstream> namespace Scoreboard { namespace Graphics { std::string ScoreboardOverlay(scoreboard_display_data_list_t sbddl) { constexpr auto no_save_text = "No saved scores."; const auto score_attributes_text = { ...
#include "scores.hpp" #include "color.hpp" #include <algorithm> #include <array> #include <fstream> #include <sstream> namespace { using namespace Scoreboard; bool generateFilefromScoreData(std::ostream &os, Score score) { os << score; return true; } Scoreboard_t generateScorefromFileData(std::istream &is) { Sc...
#include "statistics-graphics.hpp" #include "color.hpp" #include <array> #include <iomanip> #include <sstream> namespace Statistics { namespace Graphics { std::string AskForPlayerNamePrompt() { constexpr auto score_prompt_text = "Please enter your name to save this score: "; constexpr auto sp = " "; std:...
#include "statistics.hpp" #include "color.hpp" #include "scores-graphics.hpp" #include "scores.hpp" #include "statistics-graphics.hpp" #include <algorithm> #include <array> #include <fstream> #include <sstream> namespace Statistics { namespace { std::string receive_input_player_name(std::istream &is) { std::string...
#include "tile-graphics.hpp" #include "color.hpp" #include "tile.hpp" #include <cmath> #include <iomanip> #include <sstream> #include <vector> namespace Game { namespace { Color::Modifier tileColor(ull value) { std::vector<Color::Modifier> colors{red, yellow, magenta, blue, cyan, yellow, ...
#include "tile.hpp" namespace Game {} // namespace Game
//#include "game.hpp"