题解 | #找出字符串中第一个只出现一次的字符# 3ms题解

找出字符串中第一个只出现一次的字符

https://www.nowcoder.com/practice/e896d0f82f1246a3aa7b232ce38029d4

#include <stdio.h>
#include <string.h>

struct stu{
    char c;
    int tim;
};

int main() {
    struct stu st[100000];
    char a[10000]={'\0'};
    int count[1000] = {0};
    scanf("%s",a);
    int cnt;
    int tim_cnt = 0;;
    for(int i=0;i<strlen(a);i++){
        cnt = a[i];
        int cnt_stu = count[cnt];
        if(st[cnt_stu].tim == 0) {
            st[++tim_cnt].c = a[i];
            st[tim_cnt].tim = 1;
            count[cnt] = tim_cnt;
        } else {
            (st[cnt_stu].tim)++;
        } 
    }
    for(int i=1;i<=tim_cnt;++i){
        if(st[i].tim == 1) {
            printf("%c", st[i].c);
            return 0;
        }
    }
    printf("-1");
    return 0;
}

#3ms#
全部评论

相关推荐

2025-11-25 09:41
已编辑
Java
程序员花海_:实习和校招简历正确格式应该是教育背景+实习+项目经历+个人评价 其中项目经历注意要体现业务 实习经历里面的业务更是要自圆其说 简历模板尽可能保持干净整洁 不要太花哨的
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务