<span style="color:#0000FF;">方法1指针
#include</span> <stdio.h>
<span style="color:#0000FF;">#define</span> YES 1
<span style="color:#0000FF;">#define</span> NO 0
<span style="color:#0000FF;">#define</span> MAXLINE 100
<strong><span style="color:#7F0055;">int</span></strong> main(){
<strong><span style="color:#7F0055;">char</span></strong> data[MAXLINE];
<strong><span style="color:#7F0055;">char</span></strong> password[27];
<strong><span style="color:#7F0055;">int</span></strong> i=0;
password[0]=<span style="color:#008080;">'V'</span>;
password[5]=<span style="color:#008080;">'A'</span>;
<strong><span style="color:#7F0055;">for</span></strong>(i=1;i<=4;i++){
password[i]=password[i-1]+1;
}
<strong><span style="color:#7F0055;">for</span></strong>(i=6;i<=25;i++){
password[i]=password[i-1]+1;
}
password[i]=<span style="color:#008080;">'\0'</span>;
<strong><span style="color:#7F0055;">char</span></strong> *p=<span style="color:#008080;">"START"</span>;
<strong><span style="color:#7F0055;">char</span></strong> *c=<span style="color:#008080;">"END"</span>;
<strong><span style="color:#7F0055;">char</span></strong> *d=<span style="color:#008080;">"ENDOFINPUT"</span>;
<strong><span style="color:#7F0055;">int</span></strong> input=YES;
<em><span style="color:#008000;">//printf("%s\n",password);
</span> <span style="color:#008000;">//printf("%s\n%s\n%s\n",p,c,d);
</span></em> <strong><span style="color:#7F0055;">while</span></strong>(input==YES){
gets(data);
p=<span style="color:#008080;">"START"</span>;
i=0;
<strong><span style="color:#7F0055;">if</span></strong>(input==NO){
printf(<span style="color:#008080;">"3\n"</span>);
<strong><span style="color:#7F0055;">break</span></strong>;
}
<strong><span style="color:#7F0055;">while</span></strong>(data[i]!=<span style="color:#008080;">'\0'</span>){
<strong><span style="color:#7F0055;">if</span></strong>(data[i]==*p){
i++;
p++;
input=YES;
}<strong><span style="color:#7F0055;">else</span></strong>{
input=NO;
<em><span style="color:#008000;">//printf("1\n");
</span></em> <strong><span style="color:#7F0055;">break</span></strong>;
}
}
<em><span style="color:#008000;">//printf("1");
</span></em> <strong><span style="color:#7F0055;">if</span></strong>(input==YES){
gets(data);
<em><span style="color:#008000;">//printf("%s\n",data);
</span></em> <strong><span style="color:#7F0055;">for</span></strong>(i=0;data[i]!=<span style="color:#008080;">'\0'</span>;i++){
<em><span style="color:#008000;">//printf("%c\n",data[i]);
</span> <span style="color:#008000;">//printf("%d\n",data[i]-'A');
</span></em> <strong><span style="color:#7F0055;">if</span></strong>(data[i]>=<span style="color:#008080;">'A'</span>&&data[i]<=<span style="color:#008080;">'Z'</span>){
printf(<span style="color:#008080;">"%c"</span>,password[data[i]-<span style="color:#008080;">'A'</span>]);
<em><span style="color:#008000;">//printf("1");
</span></em> }<strong><span style="color:#7F0055;">else</span></strong>{
printf(<span style="color:#008080;">"%c"</span>,data[i]);
<em><span style="color:#008000;">//printf("2");
</span></em> }
}
printf(<span style="color:#008080;">"\n"</span>);
gets(data);
i=0;
c=<span style="color:#008080;">"END"</span>;
<strong><span style="color:#7F0055;">while</span></strong>(data[i]!=<span style="color:#008080;">'\0'</span>){
<strong><span style="color:#7F0055;">if</span></strong>(data[i]==*c){
i++;
c++;
input=YES;
}<strong><span style="color:#7F0055;">else</span></strong>{
d=<span style="color:#008080;">"ENDOFINPUT"</span>;
printf(<span style="color:#008080;">"%c\n"</span>,*c);
<strong><span style="color:#7F0055;">for</span></strong>(i=0;data[i]!=<span style="color:#008080;">'\0'</span>;i++){
<strong><span style="color:#7F0055;">if</span></strong>(data[i]==d[i]){
i++;
input=NO;
printf(<span style="color:#008080;">"1\n"</span>);
<strong><span style="color:#7F0055;">break</span></strong>;
}<strong><span style="color:#7F0055;">else</span></strong>{
input=YES;
}
}
}
}
}<strong><span style="color:#7F0055;">else</span></strong>{
d=<span style="color:#008080;">"ENDOFINPUT"</span>;
<strong><span style="color:#7F0055;">for</span></strong>(i=0;data[i]!=<span style="color:#008080;">'\0'</span>;i++){
<strong><span style="color:#7F0055;">if</span></strong>(*d==data[i]){
i++;
d++;
}<strong><span style="color:#7F0055;">else</span></strong>{
input==YES;
<em><span style="color:#008000;">//printf("2\n");
</span></em> }
}
}
}
<strong><span style="color:#7F0055;">return</span></strong> 0;
}
注意:1数组结束后面要加上‘\0’;否则打印出的数组的结果会出错♪(^∇^*)
2用指针的方法的时候声明指针时是没有*p,而是
p=<span style="color:#008080;">"START"</span>;
3注意循环不是死循环
方法2数组
#include <stdio.h>
#define YES 1
#define NO 0
#define MAXLINE 100
int main(){
char data[MAXLINE];
char password[27];
int i=0;
password[0]='V';
password[5]='A';
for(i=1;i<=4;i++){
password[i]=password[i-1]+1;
}
for(i=6;i<=25;i++){
password[i]=password[i-1]+1;
}
password[i]='\0';
char p[]="START";
char c[]="END";
char d[]="ENDOFINPUT";
int input=YES;
//printf("%s\n",password);
//printf("%s\n%s\n%s\n",p,c,d);
while(input==YES){
gets(data);
i=0;
if(input==NO){
printf("3\n");
break;
}
while(data[i]!='\0'){
if(data[i]==p[i]){
i++;
input=YES;
}else{
input=NO;
//printf("1\n");
break;
}
}
//printf("1");
if(input==YES){
gets(data);
//printf("%s\n",data);
for(i=0;data[i]!='\0';i++){
//printf("%c\n",data[i]);
//printf("%d\n",data[i]-'A');
if(data[i]>='A'&&data[i]<='Z'){
printf("%c",password[data[i]-'A']);
//printf("1");
}else{
printf("%c",data[i]);
//printf("2");
}
}
printf("\n");
gets(data);
i=0;
while(data[i]!='\0'){
if(data[i]==c[i]){
i++;
input=YES;
}else{
printf("%c\n",*c);
for(i=0;data[i]!='\0';i++){
if(data[i]==d[i]){
i++;
input=NO;
printf("1\n");
break;
}else{
input=YES;
}
}
}
}
}else{
for(i=0;data[i]!='\0';i++){
if(d[i]==data[i]){
i++;
}else{
input==YES;
//printf("2\n");
}
}
}
}
return 0;
}