for(intk=len;k>i;k--){
res[dig[k]]+=temp;
}
res[j]+=temp;
for(intk=0;k<10;k++){
res[k]+=(i-1)*temp/10;
}
}
temp/=10;
}
}
intmain(){
while(scanf("%d%d",&S,&T)!
=EOF){
if(S+T==0)break;
memset(res,0,sizeof(res));
if(S>T)swap(S,T);
solve(S-1);
for(inti=0;i<10;i++) res[i]=-res[i];
solve(T);
for(inti=0;i<10;i++)printf(i==9?
"%d\n":
"%d",res[i]);
}
return0;
}
ZOJProblemSet–2312
JapanPlotterDriver
TimeLimit:
2Seconds MemoryLimit:
65536KB
TheJapancompanyyouareworkingforproduceplotterdevicesthatcandrawnicepictures.Tosupportcustomerswhodonotpossesthespecialhardware,youwereaskedtowriteanemulationdriverthatsimulatestheworkoftheplotterandprintsthepictureonacomputerscreen.
Theplotterisdrivenwithasimplelanguageconsistingofseveraldrawingcommands:
POINTxy--makesalittlecircleatthegivencoordinates.
TEXTxytxt--displaysalineoftextatthegivencoordinates.
LINEx1y1x2y2--drawsalinebetweenthespecifiedpoints.
CLEARx1y1x2y2--erasesthegivenrectangle.
PRINT--printsanoutputpageandterminatesthecurrentjob.
TheemulationdriverusesfewASCIIcharacterstorepresentthepicture,onecharacterbeingabasicunitofthecoordinatesystem.Thetop-leftcharacterhascoordinates(1,1).TheX-axisaimstotheright,theY-axisgoesdown.
Theparticularcommandsareemulatedasfollows:
POINT:
Thedriverputsalowercaseletter"o"atthegivencoordinates.
TEXT:
Showsasinglelineoftext,thefirstcharacterispositionedatthegivencoordinatesandthetextalwaysgoesright.
LINE:
Simulatesastraightlinebetweentwopoints.Thelineisformedbyoneofthefollowingcharacters:
dash("-"),pipe("|"),slash("/"),orbackslash("\"),accordingtoitsdirection.
CLEAR:
Thedriverfillstheappropriaterectangularareawithspaces,includingtheboundingrowsandcolumns.
PRINT:
Thiscommandcausesthedrivertoprintthepicturesurroundedwithaniceframemadeofplus("+"),minus("-"),andpipe("|")characters.
Ifmoreobjectsshouldbedrawnacrossasinglecharacter,thefollowingrulesapply:
Ifthesamecharacterisdrawnseveraltimes,itisusedwithoutachange.
Ifonlypipeandminuscharactersareinvolved,theyresultintheplussign("+").
Ifonlyslashesandbackslashesareinvolved,theresultisthelowercaseletter"x".
Otherwise,theasterisk("*")isdisplayed.
Beforeascriptisgiventothedriver,itischeckedbyaspecialpreprocessor,whichrejectsallinvalidcommands.Therefore,youmayassumethatallcoordinatesarewithintherangeofthepage.Also,withtheLINEcommand,thetwopointsarealwaysdifferentandthelineisstrictlyeithervertical,horizontal,orattheangleof45ototheaxes.ThereisnoassumptionontherelativepositionofthepointsusedwiththeLINEandCLEARcommands.ThetextintheTEXTcommandisalwayscomposedonlyofuppercaseletteranddigits.
Input
Theinputconsistsofseveralscripts.EachscriptbeginswithalinecontainingtwointegersXandY,separatedwithspace,1<=X,Y<=75.Thesenumbersspecifythedimensionsofthepage.Everyotherlinecontainsexactlyoneoftheabovecommands.Thecommandsarealwaysuppercase,commandargumentsareseparatedwithonespace.
ThePRINTcommandisalwaysthelastcommandofthescript.AfterthePRINTcommand,anewscriptbegins.Theinputisterminatedwithtwozeros,whicharenotconsideredtobeascript.
Output
Foreachscript,outputtheemulatedpicture,createdasspecifiedabove.Afterthepicture,printoneblankline.
SampleInput
2010
LINE321110
LINE310112
LINE20383
TEXT68TEST
LINE1911910
LINE1710171
LINE1611610
LINE136206
CLEAR205157
LINE1811810
TEXT1210NICEPICTURE
POINT11
POINT32
PRINT
11
POINT11
CLEAR1111
PRINT
33
LINE2123
LINE1232
LINE2321
LINE3212
LINE2123
LINE1232
PRINT
00
SampleOutput
+--------------------+
|o|||||
|*/|||||
|\--*-----++++-|
|\/|||||
|\/||
|x--||
|/\||
|/TES*|||||
|/\|||||
|/\NICE****U|
+--------------------+
+-+
||
+-+
+---+
|||
|-+-|
|||
+---+
【全文翻译】
日本绘图仪驱动程序
你工作的日本公司生产的绘图设备,能画很好的图。
为了支持不具有特殊硬件的客户,你被要求写一个仿真驱动模拟工作的绘图和打印的图像在计算机屏幕上。
绘图仪驱动一个包括几个绘图命令简单的语言:
POINTxy--在xy处写一个'o'。
TEXTxytxt--从(x,y)开始,向右写入txt。
LINEx1y1x2y2–从(x1,y1)到(x2,y2)划线。
CLEARx1y1x2y2--清空矩形区域(用空格填充)。
PRINT--打印输出页并终止当前的工作。
仿真驱动程序使用几个ASCII码代表一副图,是一个基本单位的坐标系统。
左上角的字坐标(1,1)。
数据中的xy是以向右延伸为x,向下延伸为y。
特殊命令模拟如下:
点:
司机把小写字母“o”放在指定坐标。
文字:
表示一个单一的文本行,第一个字是定位在给定坐标和文字总是向右的。
线:
模拟两点之间的直线。
该线是由以下字符中的一个组成:
破折号(“-”),管(“|”),斜杠(“/”),或反斜杠(“\”),根据其方向。
明确:
驱动程序在适当的矩形区域的空间,包括行和列的边界。
打印:
此命令使驱动程序打印的图片周围有一个漂亮的框架由加(“+”),负(“-”),和管(“|”)字组成。
如果一个格子被填了多次,按照如下规则。
如果多次填充的都一样,不变。
如果只有填充的只有'-'和'|',变为'+'。
如果填充的只有'\'和'/',变为小写'x'。
其他情况一律变为'*'。
在脚本放进驱动程序之前,这是检查一个拒绝一切无效命令的特殊预处理。
因此,你可以假设所有页面范围内的坐标。
此外,在命令行,这两点都是不同的,线是严格垂直,水平,或在45°角的轴。
没有任何假设的相对位置的点与线和明确的命令。
该文本在文本命令总是只由大写字母和数字。
此外,在命令行,这两点都是不同的,线是严格垂直,水平,或与轴成45°角。
没有任何假设的点与线在相对位置有明确的命令。
该文本在文本命令中总是只由大写字母和数字组成。
输入
输入由多个脚本组成。
每个脚本开头是一行包括2个整数x与y。
分隔空间,1<=×,γ=75。
这些数字在页面有指定尺寸。
每一条线都包含一个以上的命令。
命令总是大写,命令参数是一个个分离的空间。
打印命令总是脚本的最后命令。
在打印命令后,一个新的脚本开始了。
输入2个零时脚本终止。
输出
对每个脚本,输出模拟图像,作为上述指定。
在图像后,打印一个空行。
【算法分析】
题目:
JapanPlotterDriver
提交语言:
C++
运行时间:
0ms
运行内存:
184KB
#include
#include
#defineMAXSIZE80
charmap[MAXSIZE][MAXSIZE];
intsizex,sizey;
voidsetpoint(intx,inty,charc){
if(map[y][x]=='')map[y][x]=c;
elseif(map[y][x]==c)return;
elseif((map[y][x]=='-'||map[y][x]=='+'||map[y][x]=='|')&&
(c=='-'||c=='+'||c=='|'))map[y][x]='+';
elseif((map[y][x]=='/'||map[y][x]=='x'||map[y][x]=='\\')&&
(c=='/'||c=='\\'||c=='x'))map[y][x]='x';
elsemap[y][x]='*';
}
voidline(void){
intx1,x2,y1,y2,i;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(x1==x2){
if(y1>y2){
i=y1;
y1=y2;
y2=i;
}
for(i=y1;i<=y2;++i)setpoint(x1,i,'|');
}elseif(y1==y2){
if(x1>x2){
i=x1;
x1=x2;
x2=i;
}
for(i=x1;i<=x2;++i)setpoint(i,y1,'-');
}elseif(x2-x1==y2-y1){
if(x1>x2){
i=x1;
x1=x2;
x2=i;
}
if(y1>y2){
i=y1;
y1=y2;
y2=i;
}
while(x1<=x2){
setpoint(x1,y1,'\\');
++x1;++y1;
}
}elseif(x2-x1+y2-y1==0){
if(x1>x2){
i=x1;
x1=x2;
x2=i;
}
if(y1>y2){
i=y1;
y1=y2;
y2=i;
}
while(x1<=x2){
setpoint(x1,y2,'/');
++x1;--y2;
}
}
}
voidpoint(void){
intx,y;
scanf("%d%d",&x,&y);
setpoint(x,y,'o');
}
voidtext(void){
intx,y,i;
charstr[1023];
scanf("%d%d%s",&x,&y,str);
for(i=0;str[i]&&i+x<=sizex;++i)setpoint(i+x,y,str[i]);
}
voidclear(void){
intx1,x2,y1,y2,i,j;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
if(x1>x2){
i=x1;
x1=x2;
x2=i;
}
if(y1>y2){
i=y1;
y1=y2;
y2=i;
}
for(i=y1;i<=y2;++i)for(j=x1;j<=x2;++j)map[i][j]='';
}
voidprint(void){
inti,j;
printf("+");
for(i=1;i<=sizex;++i)printf("-");
printf("+\n");
for(i=1;i<=sizey;++i){
printf("|");
for(j=1;j<=sizex;++j)putchar(map[i][j]);
printf("|\n");
}
printf("+");