QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#448644 | #254. Palindrome Numbers | YassirSalama | 100 ✓ | 0ms | 3616kb | C++14 | 1.8kb | 2024-06-19 20:32:32 | 2024-06-19 20:32:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int ll
using ull=unsigned long long;
using ll=long long;
using pii=pair<int,int>;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
const int mod=1e9+7;
#define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n";
template <typename T> istream& operator>>(istream& is, vector<T> &a) {
copy_n(istream_iterator<T>(is), a.size(), a.begin()); return is;}
#ifdef IOI
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#else
#define dbg(...) 1337;
#endif
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
const int mxn=2e5+100;
void solve(){
string s;
cin>>s;
int n=s.length();
int i=0;
int j=n-1;
auto calc = [&](int a,int b){
if(a<=b) return 0;
return 1;
};
// if(n%2==0){
while(i<j){
if(calc(s[j]-'0',s[i]-'0')){
int k=j-1;
while(s[k]=='9'){
s[k]='0';
k--;
}
s[k]+=1;
s[j]=s[i];
}else{
s[j]=s[i];
}
j--;
i++;
}
cout<<s<<endl;
// }
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int t;
cin>>t;
while(t--){
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
input:
20 1 9 10 11 12 100 101 102 1111111111111111111111111111111110 1111111111111111111111111111111111 1111111111111111111111111111111112 11111111111111111111111111111111110 11111111111111111111111111111111111 11111111111111111111111111111111112 89999999999999999990000000000000009 99999999999999999999999...
output:
1 9 11 11 22 101 101 111 1111111111111111111111111111111111 1111111111111111111111111111111111 1111111111111111221111111111111111 11111111111111111111111111111111111 11111111111111111111111111111111111 11111111111111111211111111111111111 89999999999999999999999999999999998 99999999999999999999999999...
result:
ok 20 lines