cosmos icon indicating copy to clipboard operation
cosmos copied to clipboard

Replace all ‘0’ with ‘5’ in an input Integer without using arrays for individual digits

Open syedmohdf opened this issue 9 years ago • 6 comments

syedmohdf avatar Oct 05 '17 16:10 syedmohdf

@AdiChat i m doing this

akki5031 avatar Oct 05 '17 16:10 akki5031

#include<iostream.h> int main() { int n; cin>>n; while(num!= 0) { a = num%10; num=num/10; If(!a) { num = num10 + 5; } else { num = num10 + a; } return 0; }

akritikts avatar Oct 05 '17 16:10 akritikts

where should i place the pull request

akki5031 avatar Oct 05 '17 16:10 akki5031

I am totally new to this hackathon, I didn't know where to answer that's why I commented.

On 5 Oct 2017 10:11 p.m., "abhishek kumar" [email protected] wrote:

#include <bits/stdc++.h>

using namespace std;

int main(){

int n; cin >> n;

int a = 1;

while( n / a >= 1){

a = a* 10;

int temp = n % a - n % (a / 10);

temp = temp / (a/10);

int temp2;

if(temp == 0){

  temp2 = 5 * (a/ 10);

  n = n - temp + temp2;

}

}

cout << n << endl;

}

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/OpenGenus/cosmos/issues/603#issuecomment-334522936, or mute the thread https://github.com/notifications/unsubscribe-auth/AOcJm_nQ9HjslUCA8a2svTRpVgHQiDY5ks5spQbSgaJpZM4PvUq9 .

akritikts avatar Oct 05 '17 16:10 akritikts

This should go to the unclassified section 👍

AdiChat avatar Oct 05 '17 16:10 AdiChat

Integer input_int = 1001; String str = input_int.toString(); str = str.replace('0', '5'); Integer output_integer = Integer.valueOf(str);

teqsystems avatar Oct 06 '17 00:10 teqsystems