You are not logged in. Please login at www.codechef.com to post your questions!

×

SUMTHING IOITC 2013

Can someone please tell me what's wrong with the following code?

include <iostream>

include <stdio.h>

include <vector>

include <string>

using namespace std;

signed int st(string a, signed int b) { vector<signed int=""> v; int asize=int(a.size()); int bsize=int(to_string(b).size());

if(a==to_string(b)) {
    return 0;
}

else if((asize>bsize) && (b>0) && asize>1) {
    int j=1;
    while((j<=bsize) && a.substr(0,j).size()>0) {
        v.push_back( st( a.erase(0,j), b-stoi(a.substr(0,j))));
        j++;
    }

    int i=0;
    while((v.begin()+i) < v.end()) {
        if(v[i]== -1) {
            v.erase(v.begin()+i);
        }
        else {
            i++;
        }
    }

    if(v.size()>0) {
        return (*min_element(v.begin(), v.end()) +1);
    }
    else {
        return -1;
    }
}

else if((asize==bsize) && b>0 && asize>1) {
    v.push_back( st( a.erase(0,1), b-stoi(a.substr(0,1))));
    int i=0;
    while((v.begin()+i) < v.end()) {
        if(v[i]== -1) {
            v.erase(v.begin()+i);
        }
        else {
            i++;
        }
    }

    if(v.size()>0) {
        return (*min_element(v.begin(), v.end()) +1);
    }
    else {
        return -1;
    }
}

else {
    return -1;
}

}

int main() { signed int a,b; string c; scanf("%d",&a); cin>>c; scanf("%d",&b); signed int final=st(c,b); cout<<final<<endl; return 0; }

(Sorry, the code is not documented :P)

asked 10 Jan '15, 16:50

chittaranjan's gravatar image

0★chittaranjan
1
accept rate: 0%

@chittaranjan pls explainn ur alg...

(20 Jan '15, 21:09) arpanb83★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,897
×69

question asked: 10 Jan '15, 16:50

question was seen: 618 times

last updated: 20 Jan '15, 21:09