Cup Blue Bridge recursive algorithm to improve the output ADV-308
Resource constraints
Time limit: 1.0s Memory Limit: 512.0MB
Problem Description
Writing recursive function, all integer numbers clocked out, behind each number with a minus "-", for example, integer 123, the function output 1-2-3-. The main function of the test write recursive functions.
Input Format
Enter an integer n
Output Format
The subject of the request to add a minus sign after the number n of each "-" Output
Sample input
Example of entering a subject requirements are met.
Example:
123
Sample Output
Output corresponding to the input sample above.
Example:
1-2-3-
Scale data and conventions
Enter n> 0, you must use the recursive call to implement!
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;
int recursion(string n){
if(n.length() > 0){
cout<<n[0]<<"-";
n = n.substr(1,n.length()-1);
return recursion(n);
}
}
int main(){
int n;
cin>>n;
char ch[100];
sprintf(ch,"%d",n);
string temp(ch,strlen(ch));
recursion(temp);
return 0;
}