C++98:把自己也写糊涂的代码::求助个位dalao神犇!

B2110 找第一个只出现一次的字符

__Harry_Haiyun__ @ 2023-05-20 10:10:17


#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    char letter_big[27],letter_small[27];
    letter_big[0] = 'NULL';
    letter_small[0] = 'NULL';
    for (int i = 65; i <= 90; i++) letter_big[i - 64] = char(i);
    for (int i = 97; i <= 122; i++) letter_small[i - 96] = char(i);
    int lbs[27],lss[27];
    for (int i = 0; i < s.length(); i++)
    {
        for (int j = 1; j <= 26; j++)
        {
            if (s[i] == letter_big[j]) lbs[i]++;
            if (s[i] == letter_small[j]) lss[i]++;
        }
    } 
    for (int i = 1; i <= 26; i++)
    {
        if (lbs[i] == 1 || lss[i] == 1)
        {
            cout << s[i - 1] << endl;
            return 0;
        }
    }
    cout << "no" << endl;
    return 0;
}

/*
[Warning] multi-character character constant [-Wmultichar] 8·18
[Warning] multi-character character constant [-Wmultichar] 9·20
[Warning] overflow in implicit constant conversion [-Woverflow]8·16
[Warning] overflow in implicit constant conversion [-Woverflow]9·18
*/

by dingshengyang @ 2023-05-20 10:23:09

@Harry_Haiyun 写得很没有章法


by SunTZ @ 2023-05-20 10:23:36

@Harry_Haiyun 首先,单引号放字符串,编译器已经给你报错了。


by __Harry_Haiyun__ @ 2023-05-22 13:13:17

@H20CaO 哪里?


|