Decreasing String
来源:互联网 发布:ajax获取json数据实例 编辑:程序博客网 时间:2024/06/05 22:59
Problem F: Decreasing String
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 81 Solved: 28
[Submit][Status][Web Board]
Description
You need to find a string which has exactly K positions in it such that the character at that position comes alphabetically later than the character immediately after it. If there are many such strings, print the one which has the shortest length. If there is still a tie, print the string which comes the lexicographically earliest (would occur earlier in a dictionary).
Input
The first line contains the number of test cases T. Each test case contains an integer K (≤ 100).
Output
Output T lines, one for each test case, containing the required string. Use only lower-case letters a-z.
Sample Input
Sample Output
HINT
其实也就是一个水坑题,不太好理解,尝试了几次才ac,
这样理解吧:
逆序输出k+1(准确的讲不是k+1)个字母,当k=1时输出ba,k=2时cba,k=3时dcba........,k=25时zyx.....cba,k=26时 bazyx........cba,k=26时 cbazyx.....cba
也就是一点,当k%26==0时输出的是ba不是a,其他的逆序按照字典序输出就行。
#include<cstdio>#include<cstring>#include<cctype>#include<algorithm>#include<set>#include<cstring>#include<string>#include<iostream>#include<cmath>#include<map>#include<vector>#include<stack>using namespace std;char b[105];int main(){ int t; scanf("%d",&t); while(t--){ memset(b,0,sizeof(b)); int n; scanf("%d",&n); char a='a'; for(int i=0;i<=n;i++){//我直接用数组存,然后逆序输出 b[i]=a+i%26; if(i%26==0&&i!=0){//满足条件的时候多加'b'到数组里面,构成ab b[++i]='b'; n+=1; } } for(int i=strlen(b)-1;i>=0;i--) printf("%c",b[i]); printf("\n"); } return 0;}
- Decreasing String
- zcmu1575——Decreasing String
- 【数论】Non-Decreasing Digit
- A. Slightly Decreasing Permutations
- A. Slightly Decreasing Permutations
- Slightly Decreasing Permutations
- 665. Non-decreasing Array
- 665. Non-decreasing Array
- 665. Non-decreasing Array
- 665. Non-decreasing Array
- Non-decreasing Array
- LeetCode Non-decreasing Array
- Non-decreasing Array
- leetcode-Non-decreasing Array
- leetCode-Non-decreasing Array
- 665. Non-decreasing Array
- 665. Non-decreasing Array
- 665. Non-decreasing Array
- JavaScript计算页面滚动条宽度
- java监控linux服务器CPU,内存等信息
- Build Failed! Error: Some file crunching failed see logs for details
- composer的使用
- FTP 文件共享服务
- Decreasing String
- linux下查找某个字符串所在行
- Centos6.5 服务器配置OpenVPN使用账号/密码方式验证登录
- 移动端车牌识别技术原理分析
- 写给理工科人看的乐理(一)声学基础
- Android设备屏幕锁定/解锁/屏幕点亮监听
- 扩展欧几里德解同余方程组
- springboot初始化bean扫描
- Java精选笔记_国际化