跳到正文

题解

题解:P11680 [Algo Beat Contest 001 B] Between Head and Tail

easy42约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年2月4日
收录
2025年12月12日
更新
2026年11月22日
篇幅
约 1 分钟
题目
P11680

版本

  1. v1当前

难点在于把数字转化成字符串。

这里使用 to_string 函数,可以提供一个数字给它,他会返回一个字符串。所以可以直接把数字转化成字符串,剩下直接按下标来处理和模拟就好了。

代码:

C++
#include<bits/stdc++.h>
using namespace std;
#define int long long
int t,l,r;
bool check(string s){
	if(s.size()%2==1&&s[0]==s[s.size()-1]&&s[0]==s[s.size()/2]){
		return true;
	}
	return false;
}
signed main(){
	cin>>t;
	while(t--){
		cin>>l>>r;
		for(int i=l;i<=r;i++){
			string h=to_string(i);
			if(check(h)) cout<<h<<" ";
		}
		cout<<endl;
	}
	return 0;
}
原文