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

N次WA

Posted by chrischeng021 at 2015-04-20 23:28:21 on Problem 3094
提交了N遍才PASS也算汗颜了。。。
后来才发现原来是因为如果输入#结尾我的代码会输出0
所以加了一个FLAG判断

以下附上代码:
====================================================================
#include "stdlib.h"
#include "stdio.h"
#include "string.h"


#define MAX_BUFF_SIZE 255
#define TRUE          1

int main(void){
    char input[MAX_BUFF_SIZE + 1];
    do{
        int len;
        fgets(input,MAX_BUFF_SIZE + 1,stdin);
        len = strlen(input);
        input[len - 1] = '\0';
        if(input[0] == '#'){
            break;
        }
        else{
            int i = 0,result = 0;
            int flag = -1;
            for(;i<len;i++){
                char ch = input[i];
                if(ch >= 'A' && ch <= 'Z'){
                    result += (i + 1)*(ch - 'A' + 1);
                    flag = 0;
                }
                else if(ch == ' ')
                    flag = 0;
            }
            if(0 == flag)
                printf("%d\n",result);
        }
    }
    while(TRUE);
    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