Ultraviolet A 11032 Function Overloading
Problem F |
Function Overloading |
Time limit: 3 second |
Overloading refers to the use of the same thing for different purposes. C ++ permits overloading of functions. this means we can use the same function name to create functions that perform a variety of different tasks.
Consider two functions with the same name, but different number of parameters.
IntFun (int a, int B ){
IntAns = 0;
IntI, j, cnt;
For (I= A; I <= B; I ++ ){
Cnt= 0;
For (J = 1; j <= I; j ++ ){
If (J + sod (j) = I) cnt ++;
}
If (Cnt = 0) ans ++;
}
ReturnAns;
}
IntFun (int ){
Int I;
For (I = 1; I <= a; I ++ ){
If (I + sod (I) = ){
Return I;
}
}
Return-1;
}
Where,Sod (n)= Sum of digits of n.
So,
Sod (13)= 1 + 3 = 4 and
Sod (1, 204)= 2 + 0 + 4 = 6.
Input
The first line of the input file will contain an integer that gives the number of test cases. each case will be given in one line. A line might contain one integer or two integers. all integers will be in the range [1, 10000000].
Total number of test cases will be less than 1000.
If the input contains two integers then the first function is called and if it contains one integer then the second function is called. The corresponding integers are passed as parameters.
Output
For each case, first output the case number followed by the return value of the corresponding function.
Sample Input |
Output for Sample Input |
3 101 1 9 20 |
Case 1: 91 Case 2: 5 Case 3:-1 |
#include
#include #include
#include
#include
using namespace std;const int maxn=10000005;int a[2],cnt,b[maxn],dp[maxn];string str;int sod(int num){ int p=num,ret=0; while(p) { ret+=(p%10); p/=10; } return ret;}void initial(){ for(int i=1; i
>a[cnt]) cnt++;}void solve(int co){ if(cnt==1) printf("Case %d: %d\n",co,b[a[0]]); else { if(a[0]