Etnetera Brevity Challenge CTUOpenContest2016/Gym101505K

本文介绍了一种使用C++编程语言实现的简单方法,该方法能够将一系列特定符号转换为对应的字母。通过构建一个字符数组来存储预定义的符号与字母之间的映射关系,程序能够读取输入的符号序列并输出相应的字母。此题适用于初学者练习字符串处理及数组应用。

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

题意:给出一个字母对应符号的表格,然后输入是一串符号,要求输出对应的字母。

思路:水题,用数组记录下比对下就好了。

代码:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<stack>
#include<queue>
#include<utility>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;

char ch[1010];
char alph[26][5] = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};

int main()
{
    //freopen("in.txt", "r", stdin);
    while(scanf("%s", ch) != EOF){
        char tmp[10];
        int p=0;
        int len = strlen(ch);
        int t=0;
        while(t<len){
            if(ch[t]!='/'){
                tmp[p++] = ch[t++];
            }
            else if(ch[t] == '/'){
                if(p == 0){
                    printf(" ");
                }
                else{
                    tmp[p] = '\0';
                    for(int i=0; i<26; i++){
                        if(strcmp(tmp, alph[i]) == 0){
                            printf("%c", i+'A');
                            p = 0;
                            break;
                        }
                    }
                }
                t++;
            }
            if(t == len){
                tmp[p] = '\0';
                //printf("tmp = %s\n", tmp);
                for(int i=0; i<26; i++){
                    if(strcmp(tmp, alph[i]) == 0){
                        printf("%c", i+'A');
                        p = 0;
                        break;
                    }
                }
            }
        }
        printf("\n");
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值