给定两个由小写字母构成的字符串 ss 和 tt,请你判断 ss 的反转字符串是不是 tt。
输入格式
第一行包含字符串 ss。
第二行包含字符串 tt。
输出格式
如果 ss 的反转字符串是 tt 则输出 YES,否则输出 NO。
数据范围
所有测试点满足 1≤|s|,|t|≤1001≤|s|,|t|≤100。
输入样例1:
- code
- edoc
输出样例1:
YES
输入样例2:
- abb
- aba
输出样例2:
NO
输入样例3:
- code
- code
输出样例3:
NO
- #include
- using namespace std;
- void Reverse(char *s,int n){//反转函数
- for(long long i=0,j=n-1;i
- char c=s[i];
- s[i]=s[j];
- s[j]=c;
- }
- }
- int main(){
- long long sn=0,asasn=0;
- char s[1000000],asas[1000000];
- cin>>s>>asas;
- while(s[sn]!='\0'){//求字符串长度
- sn+=1;
- }
- Reverse(s,sn);
- while(asas[asasn]!='\0'){//求字符串长度
- asasn+=1;
- }
- if(sn!=asasn){
- cout<<"NO";
- return 0;
- }
- for(long long i=0;i
- if(asas[i]!=s[i]){
- cout<<"NO";
- return 0;
- }
- }
- cout<<"YES";
- }
数对
给定一个长度为 NN 的字符串 SS,字符串中的字符下标从左到右依次为 1∼N1∼N。
请你计算共有多少个数对 (i,j)(i,j) 能够同时满足以下条件:
- 1≤i,j≤N1≤i,j≤N(ii 和 jj 可以相等)
- S[i]=S[j]S[i]=S[j]
注意,(2,1)(2,1) 和 (1,2)(1,2) 视为两个不同的数对。
输入格式
共一行,一个字符串 SS。
输出格式
一个整数,表示满足条件的数对数量。
数据范围
前三个测试点满足 1≤N≤101≤N≤10。
所有测试点满足 1≤N≤1051≤N≤105,字符串中只包含小写字母和数字。
输入样例1:
great10
输出样例1:
7
输入样例2:
aaaaaaaaaa
输出样例2:
100
- #include
- using namespace std;
- int tong[100010];
- string s;
- int main()
- {
- cin>>s;
- for(int i=0; i
size(); ++i) ++tong[s[i]]; - long long ans=0;
- for(int i=0; i<=128; ++i) ans+=1ll*tong[i]*tong[i];
- cout<
- }
构造数组
请你构造一个长度为 nn 的正整数数组 a1,a2,…,ana1,a2,…,an。
我们会给出一个长度为 n−1n−1 的由 <、>、= 组成的字符串 s1s2…sn−1s1s2…sn−1 用于约束你的构造:
- 如果 sisi 为
<,则表示你构造的数组需满足 ai- 如果 sisi 为
>,则表示你构造的数组需满足 ai>ai+1ai>ai+1。 - 如果 sisi 为
=,则表示你构造的数组需满足 ai=ai+1ai=ai+1。
你构造的正整数数组需满足上述约束的同时,保证 a1+a2+…+ana1+a2+…+an 的值尽可能小。
请你输出满足条件的正整数数组。数据保证一定有解。
输入格式
第一行包含整数 nn。
第二行包含字符串 s1s2…sn−1s1s2…sn−1。
输出格式
共一行,输出 a1,a2,…,ana1,a2,…,an。
数据范围
前 33 个测试点满足 2≤n≤62≤n≤6。
所有测试点满足 2≤n≤10002≤n≤1000。
输入样例1:
- 5
- ><><
输出样例1:
2 1 2 1 2
输入样例2:
- 5
- =<<<
输出样例2:
1 1 2 3 4
- #include
- #include
- using namespace std;
- const int N = 100010,M = 2 * N;
- int n;
- string s;
- int p[N];
- int h[N],e[M],ne[M],idx;
- void add (int a,int b) {
- e[idx] = b;
- ne[idx] = h[a];
- h[a] = idx++;
- }
- int find (int x) {
- if (p[x] != x) p[x] = find (p[x]);
- return p[x];
- }
- int dfs (int x) {
- int ans = 0;
- for (int i = h[x];~i;i = ne[i]) {
- int j = e[i];
- ans = max (ans,dfs (j) + 1);
- }
- return ans;
- }
- int main () {
- memset (h,-1,sizeof (h));
- cin >> n >> s;
- for (int i = 1;i <= n;i++) p[i] = i;
- for (int i = 0;i < s.size ();i++) {
- if (s[i] == '=') {
- int ra = find (i + 1),rb = find (i + 2);
- if (ra != rb) p[ra] = rb;
- }
- }
- for (int i = 0;i < s.size ();i++) {
- if (s[i] == '<') add (find (i + 2),find (i + 1));
- else if (s[i] == '>') add (find (i + 1),find (i + 2));
- }
- for (int i = 1;i <= n;i++) cout << dfs (find (i)) + 1 << ' ';
- return 0; }
-
相关阅读:
【ARM】中断的处理
数据结构之-队列实现
从0到1实现 OpenTiny 组件库跨框架技术
【java基础系列】13- java的面向对象
虹科案例 | 增量式编码器&紧急停止开关之案例研究(下)
解开C语言的秘密《关键字》(第六期)
DIN EN ISO 4589-2塑料 用氧指数法测定燃烧行为 第2 部分:室温试验
命令行交互性三个级别及其自动化解决方案
JDK多版本切换
ubuntu 终端 中文显示unicode码、乱码
-
原文地址:https://blog.csdn.net/GeekAlice/article/details/127813268