请问为啥60??

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

Kafka1 @ 2023-01-31 16:56:41

#include<iostream>
#include<cmath>
#include<string.h>
#include<iomanip>
#include<limits.h>
#include<algorithm>
#include<float.h>

using namespace std;

int main(){
    string s;
    getline(cin,s);
    int f[30] = {0};
     for(char c: s){
        f[c - 'a']++;
    }
    for(char c : s){
        if(f[c - 'a'] == 1){
            cout << c;
            return 0;
        }
    }
    cout << "no";
    return 0;
}

用迭代器写法只有60分,但是用正常遍历却ac了

#include<iostream>
#include<cmath>
#include<string.h>
#include<iomanip>
#include<limits.h>
#include<algorithm>
#include<float.h>

using namespace std;

int main(){
    string s;
    getline(cin,s);
    int f[30] = {0};
     for(int i =  0; i < s.length();i++){
        f[s[i] - 'a']++;
    }
    for(int i =  0; i < s.length();i++){
        if(f[s[i] - 'a'] == 1){
            cout << s[i];
            return 0;
        }
    }
    cout << "no";
    return 0;
}

请问这两种写法有啥区别吗


|