救救孩子吧,死活过不去这#8和#10
#8报错信息:
Wrong Answer.wrong answer On line 1 column 11, read 0, expected .
#10报错信息
Wrong Answer.wrong answer On line 1 column 18, read 0, expected .
都是多输出了一个零。
code
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll findnum(string s) {
ll n = 0; bool e = false;
for (auto& x : s)
if (isdigit(x))
n = n * 10 + (x - '0'), e = true;
else if (e)break;
return n;
}
string itos(ll n) {
string ls;
if (n == 0) { ls.push_back('0'); return ls; }
while (n) {
ls.push_back(n % 10 + '0');
n /= 10;
}
reverse(ls.begin(), ls.end());
return ls;
}
ll strtoll(string s) {
ll n = 0;
for (auto& x : s)n = n * 10 + (x - '0');
return n;
}
int main() {
ios::sync_with_stdio(0);
string str, str2, str3, strnum, frt, nxt, frt2, nxt2;
vector<pair<string, string>>da; char ls = 0; ll num = -1, cnt = 0, f = 0;
bool xy = true;
cin >> str; while (str.size() >= 2 && str.back() != '.') { str2.push_back(str.back()); str.pop_back(); }
if (str.back() == '.')str.pop_back(); reverse(str2.begin(), str2.end());
if (str=="1" || str=="0")xy = false, num = str[0] - '0';
for (auto& x : str)if (isdigit(x))f = 1;
if (!f)for (auto& x : str2)if (isdigit(x))f = 2;
for (auto& x : str3)if (isdigit(x))f = 2;
if (xy && !(num = findnum(str))) { while (isdigit(str.back()))str.pop_back(); }if (xy)cin >> str3;
if (xy && num == -1 && !(num = findnum(str2))) { while (isdigit(str2.back()))str2.pop_back(); }
if (xy) {
while (isdigit(str.back()))strnum.push_back(str.back()), str.pop_back();
reverse(strnum.begin(), strnum.end());
num = strtoll(strnum); cnt = num;
}
if (num == 1 || num == 0)cnt = num;
if (xy) while (!cin.fail()) {
cin >> frt >> nxt;
if (!cin.fail()) {
frt2 += str; nxt2 += str;
if (f == 1)frt2 += itos(cnt), nxt2 += itos(cnt);
frt2.push_back('.'), nxt2.push_back('.');
frt2 += str2; nxt2 += str3;
if (f == 2)frt2 += itos(cnt);
da.push_back(pair<string, string>(frt2, nxt2));
frt2.clear(); nxt2.clear(); ++cnt;
}
else break;
}
else while (!cin.fail()) {
int i = 0, j = 0;
cin >> frt >> nxt;
if (!cin.fail()) {
for (i = 0; i < frt.size(); i++) if (!isdigit(frt[i]))frt2.push_back(frt[i]); else break;
for (j = 0; j < nxt.size(); j++) if (!isdigit(nxt[j]))nxt2.push_back(nxt[j]); else break;
frt2 += itos(cnt); nxt2 += itos(cnt);
while (i + 1 < frt.size() && isdigit(frt[i]))++i;
while (j + 1 < nxt.size() && isdigit(nxt[i]))++j;
for (i; i < frt.size(); i++)if (!isdigit(frt[i]))frt2.push_back(frt[i]);
for (j; j < nxt.size(); j++)if (!isdigit(nxt[j]))nxt2.push_back(nxt[j]);
da.push_back(pair<string, string>(frt2, nxt2));
frt2.clear(); nxt2.clear(); ++cnt;
}
else break;
}
for (auto& x : da)cout << x.first << " " << x.second << endl;
return 0;
}
标程
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
char sum;
string a,b;
int num;
int main(){
cin>>sum;//输入第一个字符(注意不是字符串)
if(sum=='1'||sum=='0'){//情况①
num=sum-'0';//第一个数字
while(cin>>a>>b){
for(int i=0;i<a.size();i++){
if(a[i]>='0'&&a[i]<='9'){
if(i==a.size()-1||a[i+1]<'0'||a[i+1]>'9')cout<<num;//数字的最后一位数,输出num
}
else cout<<a[i];//不是数字
}
cout<<" ";
for(int i=0;i<b.size();i++){
if(b[i]>='0'&&b[i]<='9'){
if(i==b.size()-1||b[i+1]<'0'||b[i+1]>'9')cout<<num;
}
else cout<<b[i];
}//同上
cout<<endl;
num++;//记得要num++
}
}
else{//情况②
a="";a+=sum;//因为先前输入了sum,所以要把sum放在文件名的最前面
cin>>b;a+=b;//a此刻是完整的文件名+输入后缀
cin>>b;//输出后缀
int num1=0;//num1在这里等同于上面的num
bool p1=false,p2=false,p=false;//p是判断现在处于文件名还是后缀名中,p1表示数字在文件名后,p2表示数字在后缀名后
for(int i=0;i<a.size();i++){
if(a[i]>='0'&&a[i]<='9'){
num1=num1*10+a[i]-'0';//求第一个输出的数字
if(p==false)p1=true;
else p2=true;
}
if(a[i]=='.')p=true;//改变p
}
for(int i=0;i<b.size();i++){
if(b[i]>='0'&&b[i]<='9')p1=true;
}//同上
string m1,m2,wjm="",tzsr="",tzsc="";
int i;
for(i=0;i<a.size();i++){
if(a[i]=='.')break;
if(a[i]>'9'||a[i]<'0')wjm+=a[i];
}
for(i;i<a.size();i++){
if(a[i]!='.'&&(a[i]>'9'||a[i]<'0'))tzsr+=a[i];
}
for(int j=0;j<b.size();j++)
if(b[j]>'9'||b[j]<'0')tzsc+=b[j];
//以上为分解文件名,输入后缀和输出后缀
while(cin>>m1>>m2){
cout<<wjm;
if(p1==true)cout<<num1;//文件名后数
cout<<"."<<tzsr;
if(p2==true)cout<<num1;//后缀名后数
cout<<" "<<wjm;
if(p1==true)cout<<num1,num1++;//同上,注意num1++
cout<<"."<<tzsc;
if(p2==true)cout<<num1,num1++;//同上,注意num1++
cout<<endl;
}
}
}
请求Hack测试点,附赠关注。