Entries from 2019-05-01 to 1 month

Cheatsheat for programming competition

IN JAPANESE https://www.qoosky.io/techs/5cd1a59497

Count a substring in a string

cin >> s; found = s.find("AB"); while(found != string::npos){ cnt++; found = s.find("AB", found+1); }

Sum of divisors of an integer (~sqrt(N))

int main() { long n; cin >> n; long result = 0; for (long i=2; i<=sqrt(n); i++) { if (n%i==0) { if (i==(n/i)) result += i; else result += (i + n/i); } } cout << result << endl; }

invalid instruction mnemonic 'movzb'

I encountered this error in trying to implement comparative operator in my compiler. The error was solved by replacing "movzb" with "movzx".

Generative Grammer

program: stmt program program: ε stmt: "return" assign ";" stmt: assign ";" assign: equality assign: equality "=" assign equality: relational equality: equality "==" relational equality: equality "!=" relational relational: add relational:…