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";
}
}