ProblemA Minimizing the String

  题解:这一题读完题就写了吧。就是让你删除一个字母,使得剩下的字符组成的字符串的字典序最小;我们只要第一个当前位置的字符比下一个字符小的位置把该字符删去即可;

  参考代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 #define PI acos(-1.0) 
 4 #define RI register int
 5 #define clr(a,b) memset(a,b,sizeof a)
 6 typedef long long ll;
 7 const int INF=0x3f3f3f3f;
 8 const int maxn=2e5+10;
 9 int n;
10 char str[maxn];
11 int main()
12 {
13     scanf("%d",&n);
14     scanf("%s",str);
15     int len=strlen(str),temp=len-1;
16     for(int i=0;i<len-1;++i)
17     {
18         if(str[i]-str[i+1]>0)     
19         {
20             temp=i;
21             break;
22         }
23     }
24     for(int i=0;i<len;++i) if(i!=temp) printf("%c",str[i]);
25     printf("\n");
26     return 0;
27 }
View Code

相关文章:

  • 2021-10-16
  • 2023-04-02
  • 2021-04-28
  • 2022-03-07
  • 2021-07-13
  • 2022-02-05
  • 2022-03-01
  • 2022-12-23
猜你喜欢
  • 2022-01-10
  • 2021-06-04
  • 2021-10-07
  • 2022-02-27
  • 2022-03-05
  • 2021-09-21
  • 2021-10-29
相关资源
相似解决方案