Ultraviolet A 11032 Function Overloading

Source: Internet
Author: User

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]
      

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.