标题:字符展开【指针完成】
只看楼主
baolis
Rank: 2
来 自:呼啦瓦星
等 级:论坛游民
帖 子:39
专家分:59
注 册:2021-11-10
结帖率:100%
已结贴  问题点数:10 回复次数:1 
字符展开【指针完成】
在保存字符串时,对出现在连续位置的若干个字符,如这些字符在ASCII表中也是连续出现,则可以将这些字符使用缩写形式进行保存,以节省保存空间。例如用A-Z表示ABCDEFGHIJKLMNOPQRSTUVWXYZ,1-5表示12345,c-f表示cdef。
【要求】用指针完成
输入:包含缩写形式的字符串
输出:将缩写形式进行还原后的字符串
说明:只处理大小写字母和数字,即对于形如A-9,a-C这样的缩写不进行处理

测试用例1
输入:0-9
输出:0123456789

测试用例2
输入:a-z
输出:abcdefghijklmnopqrstuvwxyz

测试用例3
输入:G-I
输出:GHI

测试用例4
输入:ABDG-K035-9abd-h
输出:ABDGHIJK0356789abdefgh
搜索更多相关主题的帖子: 测试 字符 输入 指针 输出 
2021-11-11 11:49
diycai
Rank: 8Rank: 8
等 级:贵宾
威 望:19
帖 子:147
专家分:895
注 册:2021-5-18
得分:10 

程序代码:
#include <conio.h>
void main() 
{
    int map[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    char prev, cur, next;

    prev = 0;
    while (1)
    {
        cur = getchar();
        if (cur == '-')
        {
            next = getchar();
            if (map[prev] && map[next] && ((prev^next)<' ') && prev+1<next)
            {
                while (prev+1 < next)
                {
                    prev++;
                    printf("%c", prev);
                }
            }
            else
            {
                printf("%c", cur);
            }
            cur = next;
        }
        
        printf("%c", cur);

        if (cur == '\n')
        {
            break;
        }

        prev = cur;
    }
}
2021-11-11 12:49



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-507472-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.218017 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved