【2/5】Codeforces Round #692题解(2020-12-20)

A. In-game Chat
time limit per test: 1 second
memory limit per test: 256 megabytes

You have been assigned to develop a filter for bad messages in the in-game chat. A message is a string S of length n, consisting of lowercase English letters and characters ‘)’. The message is bad if the number of characters ‘)’ at the end of the string strictly greater than the number of remaining characters. For example, the string “)bc)))” has three parentheses at the end, three remaining characters, and is not considered bad.

Input
The first line contains the number of test cases t (1≤t≤100). Description of the t test cases follows.

The first line of each test case contains an integer n (1≤n≤100). The second line of each test case contains a string S of length n, consisting of lowercase English letters and characters ‘)’.

Output
For each of t test cases, print “Yes” if the string is bad. Otherwise, print “No”.

You can print each letter in any case (upper or lower).

Example
input
5
2
))
12
gl))hf))))))
9
gege)))))
14
)aa))b))))))))
1
)
output
Yes
No
Yes
Yes
Yes

题解
数括号


#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        string a;
        cin>>a;
        int bef=0;
        for(int i=n-1;i>=0;i--)
        {
            if(a[i]!=')')
            {
             break;
            }
            if(a[i]==')')
            {
                bef++;
            }
        }
       // cout<<"test  "<<bef<<endl;
        int num=0;
        for(int i=0;i<n-bef;i++)
        {
            num++;
        }
       // cout<<"test  "<<num<<endl;
       if(num<bef)cout<<"Yes"<<"\n";
       else cout<<"No"<<"\n";
    }
    return 0;
}

B. Fair Numbers
time limit per test:2 seconds
memory limit per test:256 megabytes

We call a positive integer number fair if it is divisible by each of its nonzero digits. For example, 102 is fair (because it is divisible by 1 and 2), but 282 is not, because it isn’t divisible by 8. Given a positive integer n. Find the minimum integer x, such that n≤x and x is fair.

Input
The first line contains number of test cases t (1≤t≤103). Each of the next t lines contains an integer n (1≤n≤1018).

Output
For each of t test cases print a single integer — the least fair number, which is not less than n.

Example
input

4
1
282
1234567890
1000000000000000000

output
1
288
1234568040
1000000000000000000

题解
从后往前验证n,不满足时n++,再从最后一位开始重新验证,直到满足题意。

#include<cstdio>
#include<iostream>
#include<string>
#include<string.h>
#include<cstdlib>
using namespace std;
int main()
{
   int t;
   cin>>t;
   while(t--)
   {
       long long int n,N,temp;
       cin>>n;
       N=n;
       while(N)
       {
           temp=N%10;
           if(temp==0||n%temp==0)
           {
               N/=10;
           }
           else{
            n++;
            N=n;
            }
       }
       cout<<n<<"\n";
   }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值