TOJ4168: Same Digits
same digits
2023-09-14 09:11:41 时间
4168: Same Digits ![分享至QQ空间](http://210.33.181.162/acmhome/forum/images/ico_qzone.gif)
Time Limit(Common/Java):1000MS/3000MS Memory Limit:65536KByte
Total Submit: 115 Accepted:62
Total Submit: 115 Accepted:62
Description
Your program will be given an integer X. Find the smallest number larger than X consisting of the same digits as X.
Input
The first line of input contains the integer X (1 ≤ X ≤ 999 999).
The first digit in X will not be a zero.
Output
Output the result on a single line. If there is no such number, output 0.
Sample Input
156
Sample Output
165
这个前缀为0没有什么卵用
贪心去实现,是不是存在,就看他后面是不是有比他大的
然后找到最新奥德那个数交换后直接sort
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int main() { char s[10]; gets(s); int n=strlen(s),i,j; for(i=n-1; i>0; i--) if (s[i]>s[i-1])break; if(!i)puts("0"); else { int x=s[i-1],f=i; for (j=i+1; j<n; j++) if(s[j]>x&&s[j]<s[f])f=j; swap(s[f], s[i-1]); sort(s+i,s+n); puts(s); } return 0; }
相关文章
- Leetcode 之Same Tree(48)
- 【异常】Zipkin server java.lang.IllegalArgumentException: Prometheus requires that all meters with the same name have the same set of tag keys. There is already an existing meter containing tag keys [meth
- [Javascript] Broadcaster + Operator + Listener pattern -- 26. Share the Same Broadcaster Values Across Multiple Listeners
- [AngularFire2] Update multi collections at the same time with FirebaseRef
- Memory limit should be smaller than already set memoryswap limit, update the memoryswap at the same
- non-compatible bean definition of same name and class
- [LeetCode] 100. Same Tree ☆(两个二叉树是否相同)
- Enlisting multiple 1-phase aware participants in the same transaction
- 3GPP TS 23502-g40 中英文对照 | 4.17.4 NF/NF service discovery by NF service consumer in the same PLMN
- BaseException: Could not construct partition: Weight vector not the same size as the number of edges
- [Leetcode]-Same Tree
- Leetcode_num3_Same Tree
- Accidental override: The following declarations have the same JVM signature (getWindow()Landroid/vie