2 条题解

  • 0
    @ 2023-11-5 9:59:19
    #include <bits/stdc++.h>
    using namespace std;
    string s,t;
    int a[150];
    int main()
    {
        cin>>s;
        for(int i=0;i<s.size();i++){
        	a[int(s[i])]++;
        	if(a[int(s[i])]>=2){
        		t=s[i];
        		break;
    		}
    	}
    	if(t==""){
    		cout<<s.size();
    	}else{
    		cout<<t;
    	}
        return 0;
    }
    
    
    • 0
      @ 2023-7-20 19:56:24
      #include <iostream>
      using namespace std;
      int book[26],pos,firstpos=-1;
      string s;
      bool flag=true;
      int main(){
          cin>>s;
          for(int i=0;i<s.length();i++){
              pos=s[i]-'a';
              if(book[pos]==0)book[pos]=1;
              else{
                  flag=false;
                  if(firstpos=-1)firstpos=pos;
              }
          }
          flag?cout<<s.length()<<endl:cout<<book[firstpos]+'a'<<endl;
          return 0;
      }
      
      • 1

      【入门】有没有重复的字符?

      信息

      ID
      975
      时间
      1000ms
      内存
      64MiB
      难度
      2
      标签
      递交数
      30
      已通过
      22
      上传者