📄 2814715_re.cpp
字号:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector <string> form;
vector <string> ::iterator it;
int check(char str[])
{
int i;
if(strcmp(str,"%d")==0||strcmp(str,"%s")==0||strcmp(str,"%%")==0)
return 0;
for(i = 0; str[i]!='\0'; i++)
if(str[i]=='%')//&&str[i+1]!='d'&&str[i+1]!='s'&&str[i+1]!='%')
return 1;
return 0;
}
int main()
{
int i, n, error;
char tmp[50001], str[50001];
string tt;
int num, no;
gets(tmp);
i = 0;error = 0;
no = num = 0;
for(i = 0; tmp[i]!='\0'; i++)
{
if(tmp[i]==' ')
continue;
n = 0;
while(tmp[i]!='\0'&&tmp[i]!=' ')
str[n++] = tmp[i++];
i--;
str[n] = '\0';
error = check(str);
if(strcmp(str,"%d")==0||strcmp(str,"%s")==0)
num++;
if(strcmp(str,"%%")==0)
strcpy(str,"%");
form.push_back(str);
}
it = form.begin();
while(gets(tmp))
{
no++;
while(it!=form.end()&&*it!="%d"&&*it!="%s")
{
if(*it=="%%")
*it = "%";
it++;
}
if(error)
continue;
if(it==form.end())
error = 1;
tt = tmp;
if(*it=="%s")
*it = tt;
else
{
int mark;
if(tmp[0]=='+')
strcpy(tmp,&tmp[1]);
mark = (tmp[0]=='-');
for(i = mark; tmp[i]!='\0'; i++)
{
if(!isdigit(tmp[i]))
error = 1;
}
if(tmp[0]=='0')
{
i = 0;
while(tmp[i]!='\0'&&tmp[i]=='0')
i++;
if(tmp[i]=='\0')
*it = "0";
else
{
tmp[0] = '-';
strcpy(&tmp[1],&tmp[i]);
if(!mark)
strcpy(tmp,&tmp[1]);
tt = tmp;
*it = tt;
}
}
else
{
strcpy(&tmp[mark],tmp);
if(mark)
tmp[0] = '-';
tt = tmp;
*it = tt;
}
}
it++;
}
if(no!=num)
error = 1;
if(error)
puts("ERROR");
else
{
for(it = form.begin(); it != form.end(); ++it)
cout<<*it<<" ";
cout<<endl;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -