2177-Lucky Numbers (easy) ZCMU

本文介绍了一种特殊类型的数字——超级幸运数,这类数字仅由4和7组成且两者的数量相等。文章详细阐述了如何找到一个不小于给定整数n的最小超级幸运数的方法,并提供了具体的实现代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description:

Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.

One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n.

Input

The only line contains a positive integer n (1≤n≤109). This number doesn't have leading zeroes.

Output

Output the least super lucky number that is more than or equal to n.

Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.

Examples

Input

4500

Output

4747

Input

47

Output

47

题意:超级幸运数字是只由数字4和7构成并且4和7的个数相同。题目要求输入一个数n,你要找出一个不小n的超级幸运数

思路:分两种情况 1.当给所数n的位数为奇数时,那么只需输出位数为n的位数+1的最小超级幸运数

            2.当给所数n的位数为偶数时,用相同位数的最大超幸运数和它比较,若仍小于n,则输出位数为n的位数+2的最小超级幸运数。若大于n,则将相同位数的最小超级幸运数通过全排列找出等于n或大于n的超级幸运数输出

代码:


#include<bits/stdc++.h>
using namespace std;
void print(int len)
{
    int i;
    for(i=1;i<=len;i++)
        printf("4");
    for(i=1;i<=len;i++)
        printf("7");
}
int main()
{
    char s[15],n[15];
    int i,len,r;
    while(~scanf("%s",s))
    {
        len=strlen(s);
        if(len%2==1)
        {
           print((len+1)/2);
           continue;
        }
        for(i=0;i<len/2;i++)
            n[i]='7';
        for(i=len/2;i<len;i++)
            n[i]='4';
        r=strcmp(s,n);
        if(r==1)
            print((len+2)/2);
        else{
            for(i=0;i<len/2;i++)
				n[i]='4';
			 for(i=len/2;i<len;i++)
				n[i]='7';
			do{
			r=strcmp(s,n);
			if(r==0||r==-1)
            {
               for(i=0;i<len;i++)
                  printf("%c",n[i]);
               break;
             }
               }while(next_permutation(n,n+len));
			}
      printf("\n");
    }
    return 0;
}

 

<think>好的,用户想查询ZCMU OJ 1318的题目详情或解题方法。首先,我需要确认自己是否了解这个题目。由于ZCMU OJ的题目可能不在我的训练数据中,我需要根据现有的引用信息进行推断,或者给出一般性的建议。 查看用户提供的引用,发现引用1提到了1614题涉及字符串替换和大小写处理,引用2是1489题关于数气球,引用3是1900题关于并查集的应用。这些信息可能帮助用户解决类似问题,但用户明确询问的是1318题,因此需要处理这个具体的问题。 首先,我需要检查是否有关于1318题的引用,但用户给出的引用中并没有直接提到1318。因此,可能需要建议用户通过题目编号查找或根据常见题型推测。例如,ZCMU的题目可能涉及数据结构、算法或字符串处理等。考虑到引用中的其他题目涉及字符串处理和并查集,1318可能属于类似类型。 接下来,我应该建议用户检查题目链接或提供更多细节,比如题目描述或输入输出样例,以便更准确地分析。同时,可以给出常见的解题思路,比如字符串处理、动态规划或图论算法,并参考现有引用中的类似题目,如字符串处理要注意大小写(引用1),数气球可能涉及计数或哈希表(引用2),并查集用于处理连通性问题(引用3)。 如果用户无法提供更多信息,可以建议搜索ZCMU OJ的在线资源或论坛,比如官方网站、GitHub题解或相关讨论区。此外,提供通用的解题步骤,如分析输入输出、确定算法、处理边界情况等,可能对用户有帮助。 最后,生成相关问题,引导用户进一步提问或提供更多细节,以便更精准地解答。</think>根据现有资料,ZCMU OJ 1318的具体题目内容未在提供的引用中直接提及。以下是帮助您解决此类编程题目的通用方法及建议: ### 常见解题思路(适用于ZCMU OJ题型) 1. **字符串处理** 若涉及字符串操作(如引用[^1]中1614题的替换和大小写处理): ```python # 示例:字符串替换时保留大小写标记 original = "HelloWorld" positions = [0 if c.isupper() else 1 for c in original] # 记录大小写位置 modified = original.lower().replace("world", "Python") result = "".join([c.upper() if positions[i]==0 else c for i,c in enumerate(modified)]) ``` 2. **并查集应用** 若涉及连通性问题(如引用[^3]中1900题的多米诺骨牌): ```python class UnionFind: def __init__(self, n): self.parent = list(range(n+1)) def find(self, x): if self.parent[x] != x: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def union(self, x, y): self.parent[self.find(y)] = self.find(x) ``` 3. **计数与统计** 若涉及数值统计(如引用[^2]中1489题的气球计数): ```python from collections import defaultdict def count_balloons(arr): counter = defaultdict(int) for num in arr: counter[num] += 1 return max(counter.values()) if counter else 0 ``` ### 建议步骤 1. **获取题目描述** 访问ZCMU OJ官网或通过题目编号搜索获取1318题的输入输出样例及具体要求。 2. **分析问题类型** - 若涉及字符串:注意大小写处理、特殊符号过滤 - 若涉及数学:推导公式或使用动态规划 - 若涉及图论:构建邻接表或应用DFS/BFS 3. **参考相似题目** 如引用的字符串替换题需额外记录大小写位置,这种技巧可推广到其他需要保留原始格式的场景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值