Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //converter from int to string
- string intToString(int n){
- if(n>=0){
- if(n<10){
- return string (string() + char(n+'0'));
- }else{
- return string(intToString(n/10) + char(n%10+'0'));
- }
- }else{
- return "-"+intToString(-n);
- }
- }
- //converter from string to int
- int stringToInt(string str){
- if(str[0]!='-'){
- if(str.length()==1){
- return int(str[0]-'0');
- }else{
- return stringToInt(str.substr(0,str.length()-1))*10 + int(str[str.length()-1]-'0');
- }
- }else{
- return 0-stringToInt(str.substr(1,str.length()-1));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement