蓝桥杯- 算法训练 Anagrams问题
来源:互联网 发布:mac git客户端 编辑:程序博客网 时间:2024/05/21 00:00
登录后才能查看试题。
算法训练 Anagrams问题
时间限制:1.0s 内存限制:512.0MB
锦囊1
锦囊2
锦囊3
问题描述
Anagrams指的是具有如下特性的两个单词:在这两个单词当中,每一个英文字母(不区分大小写)所出现的次数都是相同的。例如,“Unclear”和“Nuclear”、“Rimon”和“MinOR”都是Anagrams。编写一个程序,输入两个单词,然后判断一下,这两个单词是否是Anagrams。每一个单词的长度不会超过80个字符,而且是大小写无关的。
输入格式:输入有两行,分别为两个单词。
输出格式:输出只有一个字母Y或N,分别表示Yes和No。
输入输出样例
输入格式:输入有两行,分别为两个单词。
输出格式:输出只有一个字母Y或N,分别表示Yes和No。
输入输出样例
样例输入
Unclear
Nuclear
Nuclear
样例输出
Y
#include <iostream>#include <string>using namespace std;int main(){ string zifu1,zifu2; cin>>zifu1; cin>>zifu2; int len=zifu1.length(); int len2=zifu2.length(); //cout<<len<<endl; int i; int a1=0,b1=0,c1=0,d1=0,e1=0,f1=0,g1=0,h1=0,i1=0,j1=0,k1=0,l1=0,m1=0,n1=0,o1=0,p1=0,q1=0,r1=0,s1=0,t1=0,u1=0,v1=0,w1=0,x1=0,y1=0,z1=0; int a2=0,b2=0,c2=0,d2=0,e2=0,f2=0,g2=0,h2=0,i2=0,j2=0,k2=0,l2=0,m2=0,n2=0,o2=0,p2=0,q2=0,r2=0,s2=0,t2=0,u2=0,v2=0,w2=0,x2=0,y2=0,z2=0; for(i=0; i<len; i++) { switch(zifu1[i]) { case 'a' : a1++; break; case 'b' : b1++;break; case 'c' : c1++;break; case 'd' : d1++;break; case 'e' : e1++;break; case 'f' : f1++;break; case 'g' : g1++;break; case 'h' : h1++;break; case 'i' : i1++;break; case 'j' : j1++;break; case 'k' : k1++;break; case 'l' : l1++;break; case 'm' : m1++;break; case 'n' : n1++;break; case 'o' : o1++;break; case 'p' : p1++;break; case 'q' : q1++;break; case 'r' : r1++;break; case 's' : s1++;break; case 't' : t1++;break; case 'u' : u1++;break; case 'v' : v1++;break; case 'w' : w1++;break; case 'x' : x1++;break; case 'y' : y1++;break; case 'z' : z1++;break; case 'A' : a1++;break; case 'B' : b1++;break; case 'C' : c1++;break; case 'D' : d1++;break; case 'E' : e1++;break; case 'F' : f1++;break; case 'G' : g1++;break; case 'H' : h1++;break; case 'I' : i1++;break; case 'J' : j1++;break; case 'K' : k1++;break; case 'L' : l1++;break; case 'M' : m1++;break; case 'N' : n1++;break; case 'O' : o1++;break; case 'P' : p1++;break; case 'Q' : q1++;break; case 'R' : r1++;break; case 'S' : s1++;break; case 'T' : t1++;break; case 'U' : u1++;break; case 'V' : v1++;break; case 'W' : w1++;break; case 'X' : x1++;break; case 'Y' : y1++;break; case 'Z' : z1++;break; } } for(i=0; i<len2; i++) { switch(zifu2[i]) { case 'a' : a2++;break; break; case 'b' : b2++;break; case 'c' : c2++;break; case 'd' : d2++;break; case 'e' : e2++;break; case 'f' : f2++;break; case 'g' : g2++;break; case 'h' : h2++;break; case 'i' : i2++;break; case 'j' : j2++;break; case 'k' : k2++;break; case 'l' : l2++;break; case 'm' : m2++;break; case 'n' : n2++;break; case 'o' : o2++;break; case 'p' : p2++;break; case 'q' : q2++;break; case 'r' : r2++;break; case 's' : s2++;break; case 't' : t2++;break; case 'u' : u2++;break; case 'v' : v2++;break; case 'w' : w2++;break; case 'x' : x2++;break; case 'y' : y2++;break; case 'z' : z2++;break; case 'A' : a2++;break; case 'B' : b2++;break; case 'C' : c2++;break; case 'D' : d2++;break; case 'E' : e2++;break; case 'F' : f2++;break; case 'G' : g2++;break; case 'H' : h2++;break; case 'I' : i2++;break; case 'J' : j2++;break; case 'K' : k2++;break; case 'L' : l2++;break; case 'M' : m2++;break; case 'N' : n2++;break; case 'O' : o2++;break; case 'P' : p2++;break; case 'Q' : q2++;break; case 'R' : r2++;break; case 'S' : s2++;break; case 'T' : t2++;break; case 'U' : u2++;break; case 'V' : v2++;break; case 'W' : w2++;break; case 'X' : x2++;break; case 'Y' : y2++;break; case 'Z' : z2++;break; } } if(a1==a2&&b1==b2&&c1==c2&&d1==d2&&e1==e2&&f1==f2&&g1==g2&&h1==h2&&i1==i2&&j1==j2&&k1==k2&&l1==l2&&m1==m2&&n1==n2&&o1==o2&&p1==p2&&q1==q2&&r1==r2&&s1==s2&&t1==t2&&u1==u2&&v1==v2&&w1==w2&&x1==x2&&y1==y2&&z1==z2) { cout<<"Y"<<endl; } else { cout<<"N"<<endl; } return 0;}
0 0
- 蓝桥杯-算法训练-Anagrams问题
- 蓝桥杯---算法训练 Anagrams问题
- 蓝桥杯 算法训练 Anagrams问题
- 蓝桥杯 算法训练 Anagrams问题
- 蓝桥杯- 算法训练 Anagrams问题
- 蓝桥杯:算法训练 Anagrams问题
- 蓝桥杯- 算法训练 Anagrams问题
- 蓝桥杯 算法训练 Anagrams问题
- 蓝桥杯 算法训练 Anagrams问题
- [蓝桥杯]算法训练 Anagrams问题
- 蓝桥杯 算法训练 Anagrams问题
- 算法训练 Anagrams问题
- 算法训练 Anagrams问题
- 算法训练 Anagrams问题
- 算法训练 Anagrams问题
- 算法训练 Anagrams问题
- 算法训练 Anagrams问题
- 算法训练 Anagrams问题
- Nginx反向代理与负载均衡:节点服务器单/多虚拟机配置+实验环境搭建+原理解析
- java正则匹配中文姓名
- Bootstrap模态框遮罩问题
- 练习1
- 进程、线程相关的概念
- 蓝桥杯- 算法训练 Anagrams问题
- 我所理解的RxJava——上手其实很简单
- 大数据学习笔记之四十六 深度学习训练加速方法
- Android SDK “Connection to https://dl-ssl.google.com refused”
- Unity热更新专题(四)Unity热更新之LuaInterface(下)
- iOS代码规范(OC和Swift)
- (转)Android 手把手教您自定义ViewGroup(一)
- animation-fill-mode:both理解
- 使用 VS 2012 编译 GTest 遇到的编译错误