蓝桥杯题目-----提取用户名

本文探讨了在互联网应用中使用'@'字符提及用户的流行做法,详细解析了如何从一段文字中提取所有被提及的用户名,包括重复提及的情况,并提供了一个简单的C++实现代码示例。

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

描述

在现在的各种互联网应用中,在一段文字中使用'@'字符来提起一名用户是流行的做法。  

例如:

"@littleho submitted his code 30 times before he got passed the system test."  

其中littleho就是一个用户名。我们规定在一段文字中,'@'字符之后一段连续的、非空的大小写英文字母组成的字符串被视为提起的用户名。  

给定一段文字,请你输出其中所有提到的用户名。
输入

一行文本,只包含大小写字母、标点符号和空格。长度不超过800。
输出

按文本中的顺序输出所有提到的用户名,之间用一个空格隔开。重复提到的相同用户名也重复输出。
样例输入

    @abc:@@,@littleho's code is so confusing. @abc.

样例输出

    abc littleho abc

考字符串处理,没啥难度,注意格式

 

#include <vector>
#include <stack>
#include <string>
#include <cstring>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <queue>
#define _for(i,a,b) for(int i=a;i<b;i++)
#define _unfor(i,a,b) for(int i=a;i>=b;i--)
#define RI(a) scanf("%d",&a)
#define mset(a,val,n) for(int i=0;i<n;i++)a[i]=val;
#define mset2(a,val,n,m) for(int i=0;i<n;i++)for(int j=0;j<m;j++)a[i][j]=val;
#define FI freopen("in.txt","r",stdin)
#define FO freopen("out.txt","w",stdout)
using namespace std;
typedef long long LL;

char s[888],buf[888];
bool ischar(char c) {
    return (c>='A'&&c<='Z')||(c>='a'&&c<='z');
}

int main() {
    cin.getline(s,888);
    int n=strlen(s),flag=0;
    _for(i,0,n)if(s[i]=='@') {
        int l=++i;
        while(i<n&&ischar(s[i]))
            buf[i-l]=s[i++];
        if(strlen(buf)) {
            if(flag)cout<<" ";flag=1;
            cout<<buf;
        }
        mset(buf,0,n);
    }
}

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值