Jan 2, 2015 at 2:44am Jan 2, 2015 at 2:44am UTC
input : 325
output : 3332255555
i was trying for so long but i cant get the right code ... im out ... please can someone do it ? im absolutely angry because its not hard. please.
Jan 2, 2015 at 2:56am Jan 2, 2015 at 2:56am UTC
int i = a - '0' ; // '0' = 0
Jan 2, 2015 at 3:02am Jan 2, 2015 at 3:02am UTC
how are input and output related?
Jan 2, 2015 at 4:44am Jan 2, 2015 at 4:44am UTC
string s;
cin >> s; // 325
now, print s[i] i times.
Jan 2, 2015 at 6:01am Jan 2, 2015 at 6:01am UTC
std::string s;std::cin>>s;for (auto t: s)for (int i=0;i<t-'0' ;++i)std::cout<<t;
Edit: whoops, a reference to the char is unnecessary...
Last edited on Jan 2, 2015 at 6:03am Jan 2, 2015 at 6:03am UTC
Jan 2, 2015 at 3:44pm Jan 2, 2015 at 3:44pm UTC
can someone give me whole code ?
Jan 2, 2015 at 4:51pm Jan 2, 2015 at 4:51pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#include <iostream>
#include <string>
using namespace std;
int main(){
string wholeNumber;
cin >> wholeNumber;
for (auto num : wholeNumber){
for (int i = 0; i < num - '0' ; ++i)
{
cout << num;
}
}
system("PAUSE" );
}
Last edited on Jan 2, 2015 at 4:53pm Jan 2, 2015 at 4:53pm UTC
Jan 2, 2015 at 10:02pm Jan 2, 2015 at 10:02pm UTC
This isn't supposed to be a "please do my homework" forum :D
Jan 2, 2015 at 11:37pm Jan 2, 2015 at 11:37pm UTC
bugbyte its not homework i code cuz i love it its my hobby i code for some months but sometimes i have problems so i cant do an easy task i could get point how to code exactly this and also what is auto num : ?
Jan 3, 2015 at 11:12am Jan 3, 2015 at 11:12am UTC
For 'auto' you will require to enable C++11 with your compiler (if not happened already).
It basically finds the Type for you. You could also write:
for (char num : wholeNumber) ...
In that case, sorry for jumping to conclusions.