Commits

committed 96f4cf8

Some more code cheff problems done

cheff/CMD01.cpp

`+#include <iostream>`
`+#include <cstdio>`
`+#include <stack>`
`+#include <math.h>`
`+`
`+using namespace std;`
`+`
`+int reverse(int num) {`
`+  int x = num;`
`+  stack <int> digits;`
`+  int rev_num = 0;`
`+`
`+  while(x%10 == 0) x = x/10;`
`+`
`+  while(x) {`
`+    digits.push(x%10);`
`+    x = x/10;`
`+  }`
`+`
`+  int count = 0;`
`+`
`+  while(!digits.empty()) {`
`+    rev_num = rev_num + digits.top()*pow(10, count);`
`+    digits.pop();`
`+    count++;`
`+  }`
`+`
`+  return rev_num;`
`+}`
`+`
`+int main() {`
`+`
`+  int T;`
`+  cin >> T;`
`+  int a, b;`
`+  while(T--) {`
`+    scanf("%d%d", &a, &b);`
`+    cout << reverse(reverse(a)+reverse(b)) << endl;`
`+  }`
`+`
`+  return 0;`
`+}`

cheff/DRAGNXOR.cpp

`+#include <iostream>`
`+#include <cstdio>`
`+#include <bitset>`
`+#include <stdlib.h>`
`+#define ULL unsigned long long`
`+`
`+using namespace std;`
`+`
`+int main() {`
`+  int T;`
`+  cin >> T;`
`+  int n, bits;`
`+  ULL a, b, sol;`
`+  while(T--) {`
`+    scanf("%d%llu%llu", &n, &a, &b);`
`+    bitset <30> na = a;`
`+    bitset <30> nb = b;`
`+    bits = abs(n-na.count()-nb.count());`
`+    // cout << na.count() << " " << na.count() << " " << bits << endl;`
`+    sol = 0;`
`+    for(int t=bits; t<n; t++)`
`+      sol+=1<<t;`
`+`
`+    printf("%llu\n",sol);`
`+  }`
`+`
`+  return 0;`
`+}`

cheff/EASYPROB.txt

`+137=2(2(2)+2+2(0))+2(2+2(0))+2(0)`
`+1315=2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2(0))+2+2(0)`
`+73=2(2(2)+2)+2(2+2(0))+2(0)`
`+136=2(2(2)+2+2(0))+2(2+2(0))`
`+255=2(2(2)+2+2(0))+2(2(2)+2)+2(2(2)+2(0))+2(2(2))+2(2+2(0))+2(2)+2+2(0)`
`+1384=2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2)+2(2(2)+2(0))+2(2+2(0))`
`+16385=2(2(2+2(0))+2(2)+2)+2(0)`
`+`

cheff/HAREJUMP.cpp

`+#include <iostream>`
`+#include <cstdio>`
`+`
`+using namespace std;`
`+`
`+int steps[4] = {1, 2, 3, 8};`
`+`
`+int jumps(int total, int i) {`
`+`
`+  cout << total << " " << i << endl;`
`+`
`+  int sum = 0;`
`+  if (i > 3) return 0;`
`+`
`+  if(total - steps[i] == 0) {`
`+    i++;`
`+    return 1;`
`+  }`
`+  if(total-steps[i] < 0) {`
`+    i++;`
`+    return 0;`
`+  }`
`+  if(total-steps[i] > 0) sum+jumps(total-steps[i], i);`
`+  `
`+  cout << "i " << i << endl;`
`+  return sum;`
`+}`
`+  `
`+int main() {`
`+  `
`+  cout << jumps(13, 0) << endl;`
`+  return 0;`
`+}`
`+  `

cheff/HAREJUMP_pr.cpp

`+#include <iostream>`
`+`
`+using namespace std;`
`+`
`+int coins[3] = {1, 2, 8};`
`+`
`+int findposs(int money, int maxcoin)`
`+{`
`+    int sum = 0;`
`+    if(maxcoin == 2) return 1;`
`+    for(int i = maxcoin; i<3;i++)`
`+    {`
`+        if (money-coins[i] == 0) sum+=1;`
`+        if (money-coins[i] > 0) sum+=findposs(money-coins[i], i);`
`+    }`
`+    return sum;     `
`+}`
`+`
`+int main()`
`+{`
`+    cout<<findposs(13, 0)<<endl;`
`+}`

cheff/NSIT13.cpp

`+#include <iostream>`
`+#include <cstdio>`
`+`
`+using namespace std;`
`+`
`+int main() {`
`+  int T = 10;`
`+  while(T--) {`
`+    int locations[42] = {0};`
`+    int val, mod;`
`+    for(int i = 0; i < 10; i++) {`
`+      cin >> val;`
`+      mod = val%42;`
`+      locations[mod]++;`
`+    }`
`+    int count = 0;`
`+    for(int i = 0; i < 42; i++)`
`+      if (locations[i] != 0) count++;`
`+`
`+    cout << count << endl;`
`+  }`
`+  `
`+  return 0;`
`+`
`+}	`
`+      `
`+`
`+`

cheff/ONP.cpp

`+#include <iostream>`
`+#include <cstdio>`
`+#include <stack>`
`+`
`+using namespace std;`
`+`
`+int main() {`
`+  int T;`
`+  cin >> T;`
`+  while(T--) {`
`+    char exp[400];`
`+    stack <int> sym;`
`+    int s, count = 0;`
`+    scanf("%s", exp);`
`+`
`+    while(*(exp+count) != '\0') {`
`+      s = (int)*(exp+count);`
`+      if(s > 96 && s < 123)`
`+	cout << (char) s;`
`+      else if(s == 43 || s == 45) sym.push(s);`
`+      else if(s == 42 || s || 47) {`
`+	if(sym.top() == 43 || sym.top() == 45) sym.push(s);`
`+	else if(sym.top() == 42 || sym.top()== 47) {`
`+	  cout << (char) sym.top();`
`+	  sym.pop();`
`+	  sym.push(s);`
`+	}`
`+      count++;`
`+    }`
`+  }`
`+  return 0;`
`+}`
`+`
`+`

cheff/RESN04.cpp

`+#include <iostream>`
`+`
`+using namespace std;`
`+`
`+int times(int pile, int index) {`
`+  int count = 0;`
`+  while(pile >= index) {`
`+    pile -= index;`
`+    count++;`
`+  }`
`+`
`+  return count;`
`+}`
`+`
`+int main() {`
`+`
`+  int T;`
`+  cin >> T;`
`+  while(T--) {`
`+    int count = 0;`
`+    int piles, index = 1;`
`+    int pile;`
`+    cin >> piles;`
`+    while(piles--) {`
`+      cin >> pile;`
`+      count += times(pile, index);`
`+      index++;`
`+    }`
`+    if(count % 2 == 1) cout << "ALICE" << endl;`
`+    else cout << "BOB" << endl;`
`+  }`
`+  `
`+`
`+  return 0;`
`+}`
`+`
`+`
`+`

cheff/TLG.cpp

`+#include <iostream>`
`+#include <cstdio>`
`+#include <stdlib.h>`
`+`
`+using namespace std;`
`+`
`+int main() {`
`+  int N;`
`+  cin >> N;`
`+  int winner, lead;`
`+  int maxwinner = 0, maxlead = 0;`
`+  int sum1 = 0, sum2 = 0, p1, p2;`
`+  while(N--) {`
`+    cin >> p1 >> p2;`
`+    sum1 += p1;`
`+    sum2 += p2;`
`+    if(sum1 < sum2) {`
`+      lead = sum2 - sum1;`
`+      winner = 2;`
`+    }`
`+    else {`
`+      lead = sum1 - sum2;`
`+      winner = 1;`
`+    }`
`+`
`+    maxlead = maxlead > lead ? maxlead : lead;`
`+    if(maxlead == lead) maxwinner = winner;`
`+  }`
`+`
`+  cout << maxwinner << " " << maxlead << endl;`
`+}`
`+      `