QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#485071 | #7698. ISBN Conversion | Foedere0 | WA | 0ms | 3872kb | C++23 | 1.4kb | 2024-07-20 11:22:39 | 2024-07-20 11:22:41 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
void solve(){
string s;
cin>>s;
int len=s.size();
if(s[0]=='-'||s[len-1]=='-'){ //开头和结尾不能有'-'
cout<<"invalid"<<endl;
return;
}
if(s.find("--")!=-1||s.find("---")!=-1){ //不能有连续的'-'
cout<<"invalid"<<endl;
return;
}
int cnt=0; //记录'-'数量
int sum=0;
int j=0;
for(int i=0;i<len-1;i++){
if(s[i]=='-'){
cnt++;
continue;
}
j++;
if(s[i]>='0'&&s[i]<='9'){
sum+=(s[i]-'0')*(10-j+1);
}
}
if(cnt>3){
cout<<"invalid"<<endl;
return;
}
if(cnt==3){
if(s[len-2]!='-'){
cout<<"invalid"<<endl;
return;
}
}
/*if(j!=9){
cout<<"invalid"<<endl;
return;
}*/
if(s[len-1]=='X'){
sum+=10;
}
if(s[len-1]>='0'&&s[len-1]<='9'){
sum+=(s[len-1]-'0');
}
if(sum%11!=0){
cout<<"invalid"<<endl;
return;
}
s="978-"+s;
int len2=s.size();
int sum2=0;
int k=0;
for(int i=0;i<len2-1;i++){
if(s[i]=='-') continue;
k++;
if(k%2){
sum2+=(s[i]-'0');
}
else{
sum2+=(s[i]-'0')*3;
}
}
for(int i=0;i<=9;i++){
if((sum2+i)%10==0){
char o='0'+i;
s[len2-1]=o;
break;
}
}
cout<<s<<endl;
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int T=1;
cin>>T;
while(T--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
input:
4 3-540-4258-02 039428013X 3-540-42580-2 0-14-028333-3
output:
invalid 978-0394280134 978-3-540-42580-9 invalid
result:
ok 4 lines
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3872kb
input:
25 ---------- ----------- ------------ ------------- XXXXXXXXXX XXXXXXXXXXX XXXXXXXXXXXX XXXXXXXXXXXXX ---------X ----------X -----------X 01234567890 012345678901 0123456789012 -0123456789- 0123456789- -0123456789 01--23456789 012345678--9 0123456789-- --0123456789 98765432-1 987-654-321 87-645-32-...
output:
invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid 978-01234567897 invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid invalid
result:
wrong answer 12th lines differ - expected: 'invalid', found: '978-01234567897'