电话号码
分析:
允许对字符进行删除操作,那么只要从头开始遍历,只要找到‘8’,判断一下是否是在前11个位置就行了
AC代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n; cin>>n;
while(n--)
{
int length;
string str;
cin>>length;
cin>>str;
if(length<11)
{
cout<<"NO"<<endl;
continue;
}
//
for (int i = 0; i < length-1; ++i)
{
if(str[i]=='8')
{
if(length-i>=10)
{
cout<<"YES"<<endl;
break;
}
}
if(i==length-10)
cout<<"NO"<<endl;
}
}
return 0;
}
题目描述:
分析:
AC代码
#include <iostream>
#include <algorithm>
#include <string>
//#include <bits/stdc++.h>
using namespace std;
struct node
{
int x, y;
}a[100005];
bool cmp(node a, node b)
{
return a.y<a.y;
}
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; ++i)
{
cin >> a[i].x >> a[i].y;
}
sort(a, a + n, cmp);
// long long maxn = a[0].y + a[n - 1].y;
int maxn = a[0].y + a[n - 1].y;
for (int i = 0, j = n - 1; i <= j;)
{
if (i == j){
maxn = max(maxn, a[i].y + a[j].y);
break;
}
while (a[i].x >= a[j].x && i<j) {
a[i].x = a[j].x;
maxn = max(maxn, a[i].y + a[j].y);
j--;
}
while (a[i].x < a[j].x && i<j){
a[j].x = a[i].x;
maxn = max(maxn, a[i].y + a[j].y);
i++;
}
}
cout << maxn << endl;
return 0;
}
题目描述:打印最小非零数
分析:将输入的序列排序,再将相邻的数列依次相减即可
AC代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
cin>>n>>k;
vector<int> v;
for (int i = 0; i < n; ++i)
{
int cur;
cin>>cur;
v.push_back(cur);
}
sort(v.begin(),v.end());
int sum=0;
for (int i = 0; i < k; ++i)
{
if(v[i]-sum != 0)
{
sum+=v[i];
cout<<(v[i]-sum)<<endl;
}
// else
}
return 0;
}
题目描述: 异或值
分析:
这道题目暴力也可以过部分样例
题解链接:https://blog.csdn.net/hypHuangYanPing/article/details/80612781