Skip to content

Commit

Permalink
bishops
Browse files Browse the repository at this point in the history
  • Loading branch information
ramjeet saran committed Aug 20, 2015
1 parent c8b0c43 commit 3936da7
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions Readme
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ http://www.spoj.com/users/raj94/
30) GIRLSNBS
31) INVCNT
32) NGM
33) BISHOPS
57 changes: 57 additions & 0 deletions bishops.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//DATE: 20/08/2015
//Author: Ramjeet Saran
//http://www.spoj.com/problems/BISHOPS/

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <stack>
#include <vector>
#include <cmath>
#include <cstring>
#include <map>
#include <string>

# define MAX(a,b) a>b ? a : b;
# define MIN(a,b) a<b ? a : b;
# define lli long long int
# define ull unsigned long long int
# define FOR(i,j,n) for(i = j; i < n; i++)

using namespace std;

int main(){

string N;
while(getline(cin,N)){

int lenN = N.length();
int borrow = 1;
int i = 0;
if(lenN == 1 && (N[0] == 48 || N[0] == 49))
cout<<N[0]<<endl;
else {
while(i < lenN){
int mool = (N[lenN - i -1] - '0') - borrow;
borrow = mool < 0 ? 1: 0;
N[lenN - i -1] = mool < 0 ? mool + 10 + '0' : mool + '0';
i++;
}
int carry = 0;
int lenO = 0;
string out;
for(i = lenN; i >= 0; i--){
int mool = (N[i] - '0') + (N[i] - '0') + carry;
carry = mool > 9 ? 1 : 0;
out[lenO++] = (mool % 10) +'0';
}
if(carry)
out[lenO++] = '1';

for(int i = lenO - 1; i > 0; i--)
cout<<out[i];
cout<<endl;
}
//cin>>N;
}
}

0 comments on commit 3936da7

Please sign in to comment.