Codeforces--50B--Choosing Symbol Pairs
题目描述:
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that
1 ≤ i, j ≤ N
S[i] = S[j], that is the i-th symbol of string S is equal to the j-th.
输入描述:
The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105.
输出描述:
Print a single number which represents the number of pairs i and j with the needed property. Pairs (x, y) and (y, x) should be considered different, i.e. the ordered pairs count.
输入:
great10
aaaaaaaaaa
输出:
7
100
题意:
计算字符串中Si = Sj的次数
题解:
对于每一种字符,它的个数为t,则它的贡献为t * t
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<map>
using namespace std;const int maxn = 100000 + 5;
char s[maxn];
typedef long long ll;int main(){while(scanf("%s",s)!=EOF){map<char,int> mp;int l = strlen(s);for(int i = 0; i < l; i ++){mp[s[i]] ++;}ll sum = 0;map<char, int>::iterator it;for(it = mp.begin(); it != mp.end(); it++){int t = it->second;sum += 1ll * t * t;}printf("%I64d\n",sum);}return 0;
}
Codeforces--50B--Choosing Symbol Pairs相关推荐
- (寒假CF)Choosing Symbol Pairs
//我觉得这题好像跟我理解的不太一样啊T ^ T,有点郁闷 Description There is a given string S consisting of N symbols. Your ta ...
- Choosing Symbol Pairs
Description There is a given string S consisting of N symbols. Your task is to find the number of or ...
- codeforces 794E Choosing Carrot
目录 codeforces 794E Choosing Carrot 题意 题解 Code codeforces 794E Choosing Carrot 题目传送门 题意 给出一个长度为\(n\)的 ...
- 【Codeforces - 769D】k-Interesting Pairs Of Integers(暴力,统计,思维,数学,异或)
题干: Vasya has the sequence consisting of n integers. Vasya consider the pair of integers x and y k-i ...
- codeforces:C. Foe Pairs【排列 + 子数组个数问题 + 排序 + 二分】
分析 求得是不能包含任意两个数字得子数组个数 那么排列问题当然要求数字对应得下标,把查询得两个数都转换为下标 得到m组下标对 然后按右端点排序 我们得思路是固定r,看看l最左到哪里 那么我们固定r,肯 ...
- 【Codeforces 652 C Foe Pairs 】
C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- codeforces 1569 D. Inconvenient Pairs
contents: 题意 思路 AC代码 题意 曼哈顿距离知道不? 先来一张图 看到这些小点点没 上面的数字代表出现的顺序 然后横竖的线代表路 点点代表人 人与人之间如果走的路线不是曼哈顿距离那就是一 ...
- 14. Setting Ta and RTO【设置Ta和RTO】
原文链接:https://datatracker.ietf.org/doc/html/rfc8445#section-14 14. Setting Ta and RTO[设置Ta和RTO] 14.1. ...
- 【Linux】GCC程序开发工具(下)
00. 目录 文章目录 00. 目录 01. GCC的二进制工具 02. objdump 03. objcopy命令 04. 总结 05. 附录 01. GCC的二进制工具 objdump 显示目标文 ...
最新文章
- Cocos2d-x3.1颗粒使用
- python提示keyerror 13372,Python 学习笔记之—— Pandas 库
- android源码出现的@字符意义总结
- C++assert 断言
- three 天空球_javascript – 分配给相机的three.js天空盒
- mybatis plus骚操作之逻辑删除
- 手机屏坏了怎么把里面存东西取出来_三年来,这十八个有关MT4的问题被问了三千遍...
- 存储器和 I/O 端口有哪两种编址方式?简要说明各自特点
- 成也英雄,败也英雄—Sun前CEO Scott Mc- Nealy
- 计算机禁止安装游戏软件,win10禁止安装,手把手教你win10如何设置禁止安装软件...
- android渗透测试工具drozer,利用drozer进行Android渗透测试
- 2018年湘潭大学程序设计竞赛 - 题解
- 示波器wvf导入matlab,运动控制系统实验
- 学校网站建设的必要性
- 现在国内程序员的工资是什么行情?
- 结合量价持仓分析的股指期货日内交易策略
- 如何改变计算机桌面字体,怎么调整电脑桌面字体
- 南京南汽技工学校计算机专业是啥,计算机中心附近技术类学校
- 关于马化腾的故事(转自知乎)
- 对于DFA、NFA理解