记录编号 |
18125 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[NOIP 2007]字符串的展开 |
最终得分 |
100 |
用户昵称 |
Oo湼鞶oO |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.005 s |
提交时间 |
2010-09-08 14:34:37 |
内存使用 |
0.28 MiB |
显示代码纯文本
#include <fstream>
#define I_F "expand.in"
#define O_F "expand.out"
using namespace std;
char s[200];
char wt[200][100];
bool p[200];
short p1,p2,p3;
ofstream fout(O_F);
void Input();
short slen(char* s);
void Expand_paint(short x, short y);
short Pdchr(char a, char b);
void Expand();
void Output_print(char x);
void Output();
int main()
{
Input();
Expand();
Output();
return 0;
}
void Input()
{
ifstream fin(I_F);
fin>>p1>>p2>>p3;
fin.get();
fin.getline(s,200);
fin.close();
}
short slen(char* s)
{
short i;
for (i=0; s[i]>0; i++);
return i;
}
void Expand_paint(short x, short y)
{
short i;
if (y==1)
if (p1==3)
for (i=(short)s[x-1]+1; i<(short)s[x+1]; wt[x][(i++)-(short)s[x-1]-1]='*');
else
for (i=(short)s[x-1]+1; i<(short)s[x+1]; wt[x][(i++)-(short)s[x-1]-1]=(char)i);
else
if (p1==3)
for (i=(short)s[x-1]+1; i<(short)s[x+1]; wt[x][(i++)-(short)s[x-1]-1]='*');
else if (p1==1)
for (i=(short)s[x-1]+1; i<(short)s[x+1]; wt[x][(i++)-(short)s[x-1]-1]=(char)i);
else
for (i=(short)s[x-1]+1; i<(short)s[x+1]; wt[x][(i++)-(short)s[x-1]-1]=(char)(i-'a'+'A'));
}
short Pdchr(char a, char b)
{
if (a<b)
if (('0'<=a)&&(b<='9'))
return 1;
else if (('a'<=a)&&(b<='z'))
return 2;
else
return 0;
else
return 0;
}
void Expand()
{
short i,t;
for (i=1; i<slen(s)-1; i++)
if (s[i]=='-')
{
t=Pdchr(s[i-1],s[i+1]);
if (t>0)
{
p[i]=true;
Expand_paint(i,t);
}
}
}
void Output_print(char x)
{
short i;
for (i=0; i<p2; i++)
fout<<x;
}
void Output()
{
short i,j;
for (i=0; i<slen(s); i++)
if (p[i])
if (p3==1)
for (j=0; j<slen(wt[i]); j++)
Output_print(wt[i][j]);
else
for (j=slen(wt[i])-1; j>=0; j--)
Output_print(wt[i][j]);
else
fout<<s[i];
fout<<endl;
fout.close();
}