• AcWing第 76 场周赛


    反转字符串

    给定两个由小写字母构成的字符串 ss 和 tt,请你判断 ss 的反转字符串是不是 tt。

    输入格式

    第一行包含字符串 ss。

    第二行包含字符串 tt。

    输出格式

    如果 ss 的反转字符串是 tt 则输出 YES,否则输出 NO

    数据范围

    所有测试点满足 1≤|s|,|t|≤1001≤|s|,|t|≤100。

    输入样例1:

    1. code
    2. edoc

    输出样例1:

    YES
    

    输入样例2:

    1. abb
    2. aba

    输出样例2:

    NO
    

    输入样例3:

    1. code
    2. code

    输出样例3:

    NO
    
    1. #include
    2. using namespace std;
    3. void Reverse(char *s,int n){//反转函数
    4. for(long long i=0,j=n-1;i
    5. char c=s[i];
    6. s[i]=s[j];
    7. s[j]=c;
    8. }
    9. }
    10. int main(){
    11. long long sn=0,asasn=0;
    12. char s[1000000],asas[1000000];
    13. cin>>s>>asas;
    14. while(s[sn]!='\0'){//求字符串长度
    15. sn+=1;
    16. }
    17. Reverse(s,sn);
    18. while(asas[asasn]!='\0'){//求字符串长度
    19. asasn+=1;
    20. }
    21. if(sn!=asasn){
    22. cout<<"NO";
    23. return 0;
    24. }
    25. for(long long i=0;i
    26. if(asas[i]!=s[i]){
    27. cout<<"NO";
    28. return 0;
    29. }
    30. }
    31. cout<<"YES";
    32. }

    数对

    给定一个长度为 NN 的字符串 SS,字符串中的字符下标从左到右依次为 1∼N1∼N。

    请你计算共有多少个数对 (i,j)(i,j) 能够同时满足以下条件:

    1. 1≤i,j≤N1≤i,j≤N(ii 和 jj 可以相等)
    2. 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
    1. #include
    2. using namespace std;
    3. int tong[100010];
    4. string s;
    5. int main()
    6. {
    7. cin>>s;
    8. for(int i=0; isize(); ++i) ++tong[s[i]];
    9. long long ans=0;
    10. for(int i=0; i<=128; ++i) ans+=1ll*tong[i]*tong[i];
    11. cout<
    12. }

    构造数组 

    请你构造一个长度为 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:

    1. 5
    2. ><><

    输出样例1:

    2 1 2 1 2
    

    输入样例2:

    1. 5
    2. =<<<

    输出样例2:

    1 1 2 3 4
    1. #include
    2. #include
    3. using namespace std;
    4. const int N = 100010,M = 2 * N;
    5. int n;
    6. string s;
    7. int p[N];
    8. int h[N],e[M],ne[M],idx;
    9. void add (int a,int b) {
    10. e[idx] = b;
    11. ne[idx] = h[a];
    12. h[a] = idx++;
    13. }
    14. int find (int x) {
    15. if (p[x] != x) p[x] = find (p[x]);
    16. return p[x];
    17. }
    18. int dfs (int x) {
    19. int ans = 0;
    20. for (int i = h[x];~i;i = ne[i]) {
    21. int j = e[i];
    22. ans = max (ans,dfs (j) + 1);
    23. }
    24. return ans;
    25. }
    26. int main () {
    27. memset (h,-1,sizeof (h));
    28. cin >> n >> s;
    29. for (int i = 1;i <= n;i++) p[i] = i;
    30. for (int i = 0;i < s.size ();i++) {
    31. if (s[i] == '=') {
    32. int ra = find (i + 1),rb = find (i + 2);
    33. if (ra != rb) p[ra] = rb;
    34. }
    35. }
    36. for (int i = 0;i < s.size ();i++) {
    37. if (s[i] == '<') add (find (i + 2),find (i + 1));
    38. else if (s[i] == '>') add (find (i + 1),find (i + 2));
    39. }
    40. for (int i = 1;i <= n;i++) cout << dfs (find (i)) + 1 << ' ';
    41. 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