程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> UVa 11032 Function Overloading

UVa 11032 Function Overloading

編輯:C++入門知識

UVa 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.

int fun(int a, int b) {

int ans = 0;

int i, 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++;

}

return ans;

}

int fun(int a) {

int i;

for(i=1; i<=a; i++){

if( i + sod(i) == a ){

return i;

}

}

return -1;

}

Where, sod(n) = sum of digits of n.

So,

sod(13) = 1 + 3 = 4 and

sod(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]

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved