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

getchar()只能读字符,scanf("%d%f%lf123%s%xxx\n%s",&a,&..)太强大了,所以慢..

Posted by 11223344 at 2008-10-13 00:40:34
In Reply To:一个scanf输入的时间消耗问题 Posted by:baseball at 2008-10-12 20:58:49
> 数据量大时,为什么用第一种情况会比第二种情况输入快好多?是因为缓冲的问题吗?
> 
> 第一种情况:
> int get_val() {
>     int ret = 0;
>     char ch;
>     while ((ch = getchar()) > '9' || ch < '0');
>     do {
>         ret = ret * 10 + ch - '0';
>     } while ((ch = getchar()) <= '9' && ch >= '0');
>     return ret;
> }
> 
> int a = get_val();
> 
> 第二种情况: 就是常见的scanf("%d", &a);

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