求调abc345 Task C
  • 板块学术版
  • 楼主ZJLmath
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/3/16 21:41
  • 上次更新2024/3/16 23:03:09
查看原帖
求调abc345 Task C
764672
ZJLmath楼主2024/3/16 21:41

我自认为没啥问题,可能是有低级错误或理解错意义?总之调了半个点没调出来

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
long long c;
string s;
long long cnt[30];
void work(){
	bool flag=0;
	for(int i=0;i<26;i++){
		if(cnt[i]!=1&&cnt[i]!=0){
			long long tmp=(cnt[i]*(cnt[i]-1))/2;
			c+=tmp;
			if(flag==0)c-=1LL,flag=1;
		}
	}
}
int main(){
	cin>>s;
	int p=s.length();
	for(int i=0;i<p;i++){
		cnt[int(s[i]-'a')]++;
	}
	work();
	long long ans=(p*(p-1)/2-c);
	cout<<ans<<endl;
	return 0;
}
2024/3/16 21:41
加载中...