Giter Club home page Giter Club logo

Comments (3)

harieamjari avatar harieamjari commented on August 24, 2024 1

Yow, may iimprove pa tong function na to.. masmaganda to kung ipapasa yung input by reference at hindi na magreturn ng string. May copying kasi na nangyayari kapag pinass by value at nireturn by value kaya medyo ikakabagal ng program mo yun.

string BIGINT::removeFrontZeros(string input){
	bool stillzero = true;
	for(int i=0;i<input.size() and stillzero;++i){
		if(input[i]=='0' and input.size()!=1){
			input.erase(i,1);
			i=-1;
		}
		if(input[i]>='1' and input[i]<='9')
			stillzero = false;
	}
	return input;
}

parang ganito.


void BIGINT::removeFrontZeros(string& input){
	bool stillzero = true;
	for(int i=0;i<input.size() and stillzero;++i){
		if(input[i]=='0' and input.size()!=1){
			input.erase(i,1);
			i=-1;
		}
		if(input[i]>='1' and input[i]<='9')
			stillzero = false;
	}
}

No. Mas babagal ang software dito dahil meron itong side effects.
https://softwareengineering.stackexchange.com/questions/15269/why-are-side-effects-considered-evil-in-functional-programming
I suggest that function takes a const datatype and returns a new value.

Tapos pala, yung input.size() ay madaming beses mong tinawag. Isave mo nalang sa variable para bumilis konti.

	BIGINT(const char* value){
		string temp = "";
		for(long i = 0;value[i]!='\0';++i)
			temp = temp+value[i];
		check(temp);
		this->data = temp;
	}

I change ang

for(long i = 0;value[i]!='\0';++i)

to:

for(long i = 0;value[i];++i)

para mas short.

Hindi mo na rin ata kailangan ng temp dito.. yung data na gamitin mo.. nakapass by reference naman yung check() eh.. at mukang hindi efficient yung pagconvert mo ng char* to string.. lalo na yung temp = temp + value[i].. suggest ko na gamitin mo na lang yung str() function.. str(value).. or try mo search ng masmabilis na paraan para maconvert yung char* to string..

int BIGINT::ones(int number, int tens){
	int ones = number-(tens*10);
	return ones;
}

int BIGINT::tens(int number){
	int tens = (int)floor((double)number/10);
	return tens;
}

masmabilis to kung ganto pre. parang same issue dun sa una kong comment.. as much as possible iwasan ang pagcopy. bukod sa sa concept ng copy at passing by reference, try mo din aralin yung concept ng const.

int BIGINT::tens const(const int& number){
	return  (int)floor((double)number/10);
}
	for(int i=0;i<n;++i)
		placeValueSums[i] = abs(placeValueSums[i]);

	string shiftedStringAnswer;
	for(int i=0;i<n;++i)
		shiftedStringAnswer.push_back(intToChar(placeValueSums[i]));

	if(!answerIsPositive)
		shiftedStringAnswer="-"+shiftedStringAnswer;

may paraan para masmabilis to. try mo sa isang loop lang.. at yung sa simula mo ilagay yung pag add nung negative sign.. sa pagconcat pala ng string masmaganda yung tmp += "x" kaysa sa tmp = tmp + "x"..

Compile the program with optimization flags -O3 or even add -march=native

from apa.

bukseng avatar bukseng commented on August 24, 2024 1

yun oh.. salamat boss. ngayon ko lang natutunan yung side effects sa c++. hehehe

from apa.

mrdcvlsc avatar mrdcvlsc commented on August 24, 2024

salamat mga lods apply ko to pag may time na

from apa.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.