Instantly share code, notes, and snippets.

# HarveyBrezinaConniffe/p1.py Created Feb 21, 2018

AIPO 2018
 import array inp0 = input() inp1 = input() a = reversed(inp1) st = '' for b in a: st += b if(inp0 == st): print('YES') else: print('NO')
 #include #include using namespace std; int main() { int numcards; cin >> numcards; map cards; for(int i = 0;i < numcards;i++) { int ccard; cin >> ccard; cards[ccard] = 1; } for(int i = 0;i <= 99;i++) { if(cards[i] != 1) { cout << i << ' '; } } cout << endl; }
 99 0 1 2
 #include using namespace std; int main() { string in; cin >> in; char lnum = 0; int length = 0; int longest = 0; for(int i = 0;i < in.length();i++) { char num = in[i]; if(num > lnum) { length++; lnum = num; } else { if(length > longest) { longest = length; } length = 1; lnum = num; } } cout << longest << endl; }
 inp = input() last = '' clength = 0 longest = 0 for i in inp: if i >= last: clength += 1 elif(clength > longest): longest = clength clength = 1 else: clength = 1 last = i if(clength > longest): longest = clength clength = 1 print(longest)
 #include #include #include #include using namespace std; long long _sieve_size; bitset<10000010> bs; vector primes; void sieve(long long upperbound) { _sieve_size = upperbound + 1; bs.set(); bs[0] = bs[1] = 0; for(long long i = 2; i <= _sieve_size; i++) if (bs[i]) { for(long long j = i*i; j <= _sieve_size; j += i) bs[j] = 0; primes.push_back((int)i); } } bool isPrime(long long N) { if(N <= _sieve_size) return bs[N]; for(int i = 0; i < (int)primes.size(); i++) if(N%primes[i] == 0) return false; return true; } int main() { sieve(2000000); int n, nums = 0; cin >> n; for(int i = 0;i <= n;i++) { if((i >= 10 && i < 20) || (i >= 100 && i < 200) || (i >= 1000 && i < 2000) || (i >= 10000 && i < 20000) || (i >= 100000 && i < 200000) || (i >= 1000000 && i < 2000000) || (i >= 10000000 && i < 20000000)) { //bool good = true; //for(int j = 2;j < i;j++) { // if(i%j == 0 && j != i) { // good = false; // break; // } //} if(isPrime(i)) nums++; } } cout << nums << endl; }
 n = 0 nums = 0 n = int(input()) for i in range(0, n): if(
 #include #include #include #include using namespace std; int main() { string road; int money; cin >> road >> money; vector sections; int numsec = 0; int csec = 0; char last; for(int i = 0;i < road.length();i++) { if(road[i] == '.' && last == 'X') { sections.push_back(csec); csec = 0; numsec += 1; } else if(road[i] == 'X') { csec += 1; } last = road[i]; } sections.push_back(csec); csec = 0; numsec += 1; sort(sections.begin(), sections.end()); int out = 0; for(int i = 0;i < numsec-money;i++) { out += sections[i]; } cout << out << endl; }
 inp = input() cols = inp.split(); green = int(cols[1]) red = int(cols[0]) GREEN = 0 RED = 1 colors = {GREEN: green, RED: red} maxlevel = 0; def work(level, color, icolornums): colornums = icolornums.copy() colornums[color] -= level; if(colornums[color] < 0): return [-1, -1]; else: n1 = work((level+1), GREEN, colornums) n2 = work((level+1), RED, colornums) if not n1[0] == n2[0]: m = max(n1[0], n2[0]) if(m == n1[0]): return [n1[0], n1[1]] else: return [n2[0], n2[1]] else: if(n1[0] == -1 and n2[0] == -1): return [level, 1] return [n1[0], n1[1]+n2[1]]; w1 = work(1, GREEN, colors) w2 = work(1, RED, colors) if(w1[0] == w2[0]): print((w1[1]+w2[1])%((10^9)+7)) else: m = max(w1[0], w2[0]); if(w1[0] == m): print(w1[1]%((10^9)+7)) else: print(w2[1]%((10^9)+7))
 green = input() red = input() level = 1 GREEN = 0 RED = 1 ccolor = GREEN colors = {GREEN: green, RED: red} maxlevel = 0; while True: if(colors[ccolor]-level < 0): maxlevel = level-1; break; else: colors[ccolor] -= level; level += 1; ccolor = RED colors = {GREEN: green, RED: red} while True: if(colors[ccolor]-level < 0): if(level-1 > maxlevel): maxlevel = level-1; break; else: colors[ccolor] -= level; level += 1; print(maxlevel)
 green = input() red = input() GREEN = 0 RED = 1 colors = {GREEN: green, RED: red} maxlevel = 0; def work(level, color, colornums): colornums[color] -= level; if(colornums[color] < 0): return level; else: return max(work((level+1), GREEN, colornums), work((level+1), RED, colornums)); print(max(work(1, GREEN, colors), work(1, RED, colors)));
Owner Author

### HarveyBrezinaConniffe commented Aug 12, 2019

 These were my solutions to the All Ireland Programming Olympiad 2018.