nyoj-1112-求次数
来源:互联网 发布:淘宝老是要输入验证码 编辑:程序博客网 时间:2024/06/03 02:10
求次数
时间限制:1000 ms | 内存限制:65535 KB
难度:2
- 描述
题意很简单,给一个数n 以及一个字符串str,区间【i,i+n-1】 为一个新的字符串,i 属于【0,strlen(str)】如果新的字符串出现过ans++,例如:acmacm n=3,那么 子串为acm cma mac acm ,只有acm出现过
求ans;
- 输入
- LINE 1: T组数据(T<10)
LINE 2: n ,n <= 10,且小于strlen(str);
LINE 3:str
str 仅包含英文小写字母 ,切长度小于10w - 输出
- 求 ans
- 样例输入
22aaaaaaa3acmacm
- 样例输出
51
- 上传者
ACM_王亚龙.
#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>#include<stdlib.h>#include<map>using namespace std;int main(){ int t; cin>>t; string str; while(t--) { int n; cin>>n; cin>>str; string s; int len=str.size(); map<string,int>tmp; int ans=0; for(int i=0; i<len-n+1; i++) { s=str.substr(i,n); if(tmp[s]==1) ans++; else tmp[s]=1; } cout<<ans<<endl; }}#include<iostream>#include<string>#include<map>#include<stdio.h>using namespace std;int main(){ string lstr; int n; cin >> n; while (n--) { map<string, int> str; int t,ans=0; cin >>t>> lstr; for (int i = 0; i <=lstr.length()+1-t; i++) { string word(lstr, i, t ); if (str.find(word) ==str.end()) str[word]; else ++ans; } printf("%d\n", ans); } return 0;}
0 0
- NYOJ--1112--求次数
- nyoj-1112-求次数
- nyoj 1112 求次数
- NYOJ 1112 求次数
- nyoj 1112 求次数
- NYOJ 1112 求次数
- nyoj-1112-求次数
- NYOJ 1112 求次数 (map)
- NYoj 1112 求次数 【水】
- NYOJ---题目1112求次数
- NYOJ 1112 求次数(map)
- NYOJ 1112 求次数(map)
- NYOJ 1112 求次数 (字符串)
- NYOJ 1112 求次数 (map)
- nyoj 1112求次数 STL
- nyoj 1112 求次数 map,数组.
- NYOJ-1112 求次数(STL)
- NYOJ 1112 求次数(map容器)
- CentOS7 下源码安装MPlayer播放器
- 27款经典的 CSS 框架分享
- java list<自定义对象>按对象的某个属性进行排序,和判断相等
- js基本功能大全
- 兔子--Android Support v4,Android Support v7,Android Support v13
- nyoj-1112-求次数
- 在mac系统安装Apache Tomcat的详细步骤
- Visual Studio, 忽略特定警告
- 基于ARM的嵌入式Linux移植真实体验(4)――设备驱动
- java基础-》Future
- WebView与Javascript无法交互问题
- UVA - 531 Compromise
- 基于ARM的嵌入式Linux移植真实体验(3)――操作系统
- C语言编程规范--代码注释