# 求助！编一个简单的小程序

sophyss1 2014-10-31 07:57:39

...全文
195 5 打赏 收藏 转发到动态 举报

5 条回复

sophyss1 2014-11-06
• 打赏
• 举报

#include<stdio.h> void main() { int x,y,z; scanf("%d %d %d",&x,&y,&z); int a1,a2,a3,a1m,a1p,a2m,a2p,a3m,a3p; int b1,b2,b3,b1m,b1p,b2m,b2p,b3m,b3p; scanf("%d %d %d",&a1,&a2,&a3); b1=1; b2=2; b3=3; while(b1<=x&&b2<=y&&b3<=z) { a1m=a1-1; a1p=a1+1; a2m=a2-1; a2p=a2+1; a3m=a3-1; a3p=a3+1; b1m=b1-1; b1p=b1+1; b2m=b2-1; b2p=b2+1; b3m=b3-1; b3p=b3+1; if(b3!=1) printf("%d %d %d %d %d %d 25/\n",a1,a2,a3,b1,b2,b3m); if(b3!=z) printf("%d %d %d %d %d %d 25/\n",a1,a2,a3,b1,b2,b3p); if(b2!=1) printf("%d %d %d %d %d %d 25/\n",a1,a2,a3,b1,b2m,b3); if(b2!=y) printf("%d %d %d %d %d %d 25/\n",a1,a2,a3,b1,b2p,b3); if(b1!=1) printf("%d %d %d %d %d %d 25/\n",a1,a2,a3,b1m,b2,b3); if(b1!=x) printf("%d %d %d %d %d %d 25/\n",a1,a2,a3,b1p,b2,b3); if(a3!=1) printf("%d %d %d %d %d %d 25/\n",a1,a2,a3m,b1,b2,b3); if(a3!=z) printf("%d %d %d %d %d %d 25/\n",a1,a2,a3p,b1,b2,b3); if(a2!=1) printf("%d %d %d %d %d %d 25/\n",a1,a2m,a3,b1,b2,b3); if(a2!=y) printf("%d %d %d %d %d %d 25/\n",a1,a2p,a3,b1,b2,b3); if(a1!=1) printf("%d %d %d %d %d %d 25/\n",a1m,a2,a3,b1,b2,b3); if(a1!=x) printf("%d %d %d %d %d %d 25/\n",a1p,a2,a3,b1,b2,b3); scanf("%d h%d %d",&a1,&a2,&a3); scanf("%d %d %d",&b1,&b2,&b3); } }
sophyss1 2014-11-06
• 打赏
• 举报

• 打赏
• 举报

• 打赏
• 举报

``````#include <conio.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
FILE *f;
int i,n,line,st;
int n1,n2,n3;
int b1,b2,b3;
int e1,e2,e3;
int w1,w2,w3;
int v1,v2,v3;
char ln[256];
char fmt[256];
char fmd[6];
char tmp[256];
char *s1,*s2,*s3,*s4;
char L,R,D;
void main(int argc,char *argv[]) {
if (argc<2) {
PMT:
printf("%s filename.ext [ParenthesesChar] [DelimiterChar]\nParenthesesChar is '(' default or '[' or '{'\nDelimiterChar is ',' default",argv[0]);
return;
}
if (argc==2) {
L='(';R=')';D=',';
} else {
switch (argv[2][0]) {
case '(':L='(';R=')';break;
case '[':L='[';R=']';break;
case '{':L='{';R='}';break;
default:goto PMT;
}
D=',';
if (argc>=4) D=argv[3][0];
}
sprintf(fmd,"%%d%c%%d",D);
if ((f=fopen(argv[1],"rt"))==NULL) {
printf("Can not open %s",argv[1]);
return;
}
line=0;
while (1) {
fgets(ln,255,f);
if (feof(f)) break;//
line++;
n=0;st=0;
for (i=0;i<(int)strlen(ln);i++) {
switch (st) {
case 0:if (ln[i]==L) st=1;break;
case 1:if (ln[i]==D) st=2;break;
case 2:if (ln[i]==R) {st=0;n++;} break;
}
}
switch (n) {
case 0:
printf("%s",ln);
break;
case 1:
s1=strchr(ln,L);
s2=strchr(s1,R);
if (s2==NULL) {
cprintf("\a\a\a missing %c in line %d",R,line);
fclose(f);
return;
}
s1[0]=0;
s1++;
s2++;
v1=sscanf(s1,fmd,&b1,&e1);
if (v1==2) {
w1=1+(int)log10((double)e1);
sprintf(fmt,"%%s%%0%1dd%%s",w1);
for (n1=b1;n1<=e1;n1++) {
printf(fmt,ln,n1,s2);
}
} else if (s1[1]==D) {
b1=s1[0];
e1=s1[2];
for (n1=b1;n1<=e1;n1++) {
printf("%s%c%s",ln,n1,s2);
}
} else {
printf("%s",ln);
}
break;
case 2:
s1=strchr(ln,L);
s2=strchr(s1,R);
if (s2==NULL) {
cprintf("\a\a\a missing %c in line %d",R,line);
fclose(f);
return;
}
s1[0]=0;
s1++;
s2++;
v1=sscanf(s1,fmd,&b1,&e1);
if (v1==2) {
w1=1+(int)log10((double)e1);
} else {
b1=s1[0];
e1=s1[2];
}

s1=strchr(s2,L);
s3=strchr(s1,R);
if (s3==NULL) {
cprintf("\a\a\a missing %c in line %d",R,line);
fclose(f);
return;
}
s1[0]=0;
s1++;
s3++;
v2=sscanf(s1,fmd,&b2,&e2);
if (v2==2) {
w2=1+(int)log10((double)e2);
} else {
b2=s1[0];
e2=s1[2];
}

strcpy(fmt,"%s");
if (v1==2) sprintf(tmp,"%%0%1dd",w1);
else strcpy(tmp,"%c");
strcat(fmt,tmp);
strcat(fmt,"%s");
if (v2==2) sprintf(tmp,"%%0%1dd",w2);
else strcpy(tmp,"%c");
strcat(fmt,tmp);
strcat(fmt,"%s");
for (n1=b1;n1<=e1;n1++) {
for (n2=b2;n2<=e2;n2++) {
printf(fmt,ln,n1,s2,n2,s3);
}
}
break;
case 3:
s1=strchr(ln,L);
s2=strchr(s1,R);
if (s2==NULL) {
cprintf("\a\a\a missing %c in line %d",R,line);
fclose(f);
return;
}
s1[0]=0;
s1++;
s2++;
v1=sscanf(s1,fmd,&b1,&e1);
if (v1==2) {
w1=1+(int)log10((double)e1);
} else {
b1=s1[0];
e1=s1[2];
}

s1=strchr(s2,L);
s3=strchr(s1,R);
if (s3==NULL) {
cprintf("\a\a\a missing %c in line %d",R,line);
fclose(f);
return;
}
s1[0]=0;
s1++;
s3++;
v2=sscanf(s1,fmd,&b2,&e2);
if (v2==2) {
w2=1+(int)log10((double)e2);
} else {
b2=s1[0];
e2=s1[2];
}

s1=strchr(s3,L);
s4=strchr(s1,R);
if (s4==NULL) {
cprintf("\a\a\a missing %c in line %d",R,line);
fclose(f);
return;
}
s1[0]=0;
s1++;
s4++;
v3=sscanf(s1,fmd,&b3,&e3);
if (v3==2) {
w3=1+(int)log10((double)e3);
} else {
b3=s1[0];
e3=s1[2];
}

sprintf(fmt,"%%s%%0%1dd%%s%%0%1dd%%s%%0%1dd%%s",w1,w2,w3);
strcpy(fmt,"%s");
if (v1==2) sprintf(tmp,"%%0%1dd",w1);
else strcpy(tmp,"%c");
strcat(fmt,tmp);
strcat(fmt,"%s");
if (v2==2) sprintf(tmp,"%%0%1dd",w2);
else strcpy(tmp,"%c");
strcat(fmt,tmp);
strcat(fmt,"%s");
if (v3==2) sprintf(tmp,"%%0%1dd",w3);
else strcpy(tmp,"%c");
strcat(fmt,tmp);
strcat(fmt,"%s");

for (n1=b1;n1<=e1;n1++) {
for (n2=b2;n2<=e2;n2++) {
for (n3=b3;n3<=e3;n3++) {
printf(fmt,ln,n1,s2,n2,s3,n3,s4);
}

}
}
break;
default:
cprintf("\a\a\a > 3 repeat in line %d",line);
fclose(f);
return;
}
}
fclose(f);
}
``````
zhouxiaofeng1021 2014-11-03
• 打赏
• 举报

3,881

• 近7日
• 近30日
• 至今