ZUFE OJ 2289 God Wang II

Description

这个世界太无聊了,于是God Wang想出了新的运算符号$,对于两个数x,y来说x$y的值等于x和y各个位置上的数字乘积之和,没有的位按0来算

比如说123$321=1*3+2*2+3*1=10,105$51=1*0+0*5+5*1=5。于是God Wang又有了新的问题,

他定义了函数F(L,R)=(((((L$(L+1))$(L+2))$(L+3)....)$R),他想要知道F(L,R)的值,现在请你来告诉他吧。

Input

输入第一行为一个正整数T(T<=1000)

接下来T行,每行两个整数L,R (0<=L<R<=2^31-1)

Output

输出T行,每行一个整数表示输出的答案

Sample Input

3

8 10

50 51

51 64

Sample Output

7

25

38

暴力跑,遇到是0了就退出循环,因为之后一定都是0。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int L,R;
int X[100];
int Y[100];
int xx,yy;

int F(int x,int y)
{
    memset(X,0,sizeof(X));
    memset(Y,0,sizeof(Y));
    xx=0;
    yy=0;
    int ans=0;
    while(x)
    {
        X[xx]=x%10;
        x=x/10;
        xx++;
    }
    while(y)
    {
        Y[yy]=y%10;
        y=y/10;
        yy++;
    }
    for(int i=0; i<max(xx,yy); i++)
        ans=ans+X[i]*Y[i];
    return ans;
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&L,&R);
        int  A=L;
        for(int i=L+1; i<=R; i++)
        {
            A=F(A,i);
            if(A==0) break;
        }
        printf("%d\n",A);
    }
    return 0;
}
时间: 2024-08-21 23:36:47

ZUFE OJ 2289 God Wang II的相关文章

ZUFE OJ 2288 God Wang I

Description God Wang 是ZUFE的神犇,有一天他想到一种神奇的变换,并且将它命名为GodW变换 对于一个数字n,该变换后的值GodW(n)为,先令X=n 第一步,如果X为个位数,GodW(n)=X,否则执行第二步; 第二步,X的奇数位置的数字之和为a,偶数位置的和为b, X=a*b, 执行第一步; 现在我们有T个询问,对于每个询问输入三个整数数l,r,x 对于每个询问请输出在[l,r]这个闭区间里的数经过该变换后为x的数有多少个 Input 第一行是一个T,表示有T组询问(T

LeetCode OJ - Reverse Linked List II

题目: Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL. Note:Given m, n satisfy the following condition:1 ≤ m ≤ n ≤ l

LeetCode OJ - Linked List Cycle II

题目: Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Follow up: Can you solve it without using extra space? 解题思路: 设置两个指针slow和fast,从head开始,slow一次一步,fast一次两步,如果fast能再次追上slow则有圈. 设slow走了n步,则fast走了2*n步,设圈长度m

&lt;LeetCode OJ&gt; 63. Unique Paths II

63. Unique Paths II My Submissions Question Total Accepted: 55136 Total Submissions: 191949 Difficulty: Medium Follow up for "Unique Paths":紧接着上一题"唯一路劲",现在考虑有一些障碍在网格中,无法到达,请重新计算到达目的地的路线数目 Now consider if some obstacles are added to the

ZUFE OJ 2301 GW I (3)

Description GW 是ZUFE的神犇,有一天他想到一种神奇的变换,并且将它命名为GW变换 对于一个数字n,该变换后的值GW(n)为,先令X=n 第一步,如果X为个位数,GW(n)=X,否则执行第二步; 第二步,X的奇数位置的数字之和为a,偶数位置的和为b, X=a*b, 执行第一步; 现在我们有T个询问,对于每个询问输入三个整数数l,r,x 对于每个询问请输出在[l,r]这个闭区间里的数经过该变换后为x的数有多少个 Input 第一行是一个T,表示有T组询问(T<=1000) 接下来T

LeetCode OJ 229. Majority Element II

Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space. Hint: How many majority elements could it possibly have? Do you have a better hint? Suggest it! [题目分析]

HDU oj A + B Problem II

郁闷了就相同的代码在HDUOJ上提交就是AC在NYOJ上提交就是WA字符串处理 #include<stdio.h> #include<string.h> #define N 1000 char x[N],y[N]; int a[N+1]; int main() { int g,h=0; scanf("%d",&g); while(g--) { int k1,k2,t=0,m,n,k,i,j,l; scanf("%s %s",x,y);

LeetCode OJ 40. Combination Sum II

Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T. Each number in C may only be used once in the combination. Note: All numbers (including target) will be posi

LeetCode OJ:Jump Game II(跳跃游戏2)

Given an array of non-negative integers, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Your goal is to reach the last index in the minimum number of jumps