Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

用gets()输出AC,用for循环字符逐个输入就Runtime Error。Why??求解

Posted by wss123 at 2011-03-04 10:18:25 on Problem 1298
#include<iostream>
#include<string>
using namespace std;

int main() {
	char ch[500];
	int i,len;
	while(1) {
		gets(ch);
/*		for(i=0;;i++){                   改用这里输入就Runtime Error
			scanf("%c", &ch[i]);
			if(ch[i]=='\n') {
				ch[i] = '\0';
				break;
			}
		}*/
		len=strlen(ch);
		if(!strcmp(ch,"START") || !strcmp(ch,"END")) continue;
		if(!strcmp(ch,"ENDOFINPUT")) break;
		for(i=0;i<len;i++) {
			if(ch[i]>'E' && ch[i]<='Z') printf("%c", ch[i]-5);
			else if(ch[i]>='A' && ch[i]<='E') printf("%c",ch[i]+21);
			else printf("%c", ch[i]);
		}
		printf("\n");
	}	
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator