codeforces 918 div4

https://codeforces.com/contest/1915

C

题意 : 给定一些数,问这些数的和是不是完全平方数(5*5这样) 

 

#include<cmath>
#include<iostream>
#define ll long long
using namespace std;
 
bool issq(ll n){
    ll root = sqrt(n);
    return root*root == n ;
  // 标准写法,其他写法有精度问题 }
int main(){ int t; cin>>t; while (t--){ ll x; cin>>x; ll sum =0; while (x--){ ll y; cin>>y; sum+=y; } if (issq(sum)) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }

D

-元音-字母 a 和 e 。它们用 V 表示。 -辅音-字母 b , c 和 d 。它们用 C 表示。

英语中有两种音节: CV (辅音后元音)或 CVC (元音前后辅音)。例如, ba 、 ced 、 bab 是音节,但 aa 、 eda 、 baba 不是音节。

例如 :  给定单词bacedbab

它会被分成几个音节:ba. cedb .bab

(点,表示一个音节边界)。

问题 : 把这个单词拆成音节。

例如,给定单词 bacedbab

它会被分成几个音节:ba. cedb .bab

(点,表示一个音节边界)。

#include "bits/stdc++.h"

using namespace std;

void solve() {
    int n;
    string s;
    cin >> n >> s;
    string t; // 倒着来
    for (int i = n - 1; i >= 0; ) {
        if (s[i] == 'a' || s[i] == 'e') {
            for (int j = 0; j < 2; j++, i--) {
                t += s[i]; // vc 往后两个数包括自身
            }
        } else {
            for (int j = 0; j < 3; j++, i--) {
                t += s[i]; // cvc 往后三个数包括自身
            }
        }
        if (i > 0) {
            t += ".";
        }
    }
    reverse(t.begin(), t.end()); //反转字符串
    cout << t << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

 

 
 

 

 

 

posted @ 2024-01-11 18:54  MKleo  阅读(18)  评论(0)    收藏  举报