最后一个字符

题目
类型:字符串
注意:使用fgets比较快

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6+5;
int dp[256];
int main(){
    char str[N];
    int k;
    scanf("%d", &k);
    getchar();
    while(k--){
        fgets(str, N, stdin);
        memset(dp, 0, sizeof dp);
        int n = strlen(str);
        for(int i = 0; i < n; i++) dp[str[i]]++;
        for(int i = 0; i < n; i++){
            if(dp[str[i]]==1){
                printf("%c\n", str[i]);
                break;
            }
        }
    }
    return 0;
}
发布了1204 篇原创文章 · 获赞 54 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/SYaoJun/article/details/105175802