24h購物| | PChome| 登入
2012-03-16 07:00:00| 人氣4,616| 回應1 | 上一篇 | 下一篇

[UVA] 10929 - You can say 11

推薦 0 收藏 0 轉貼0 訂閱站台

Problem C - You can say 11
Time Limite: 1 second


Introduction to the problem

Your job is, given a positive number N, determine if it is a multiple of eleven.

Description of the input

The input is a file such that each line contains a positive number. A line containing the number 0 is the end of the input. The given numbers can contain up to 1000 digits.

Description of the output

The output of the program shall indicate, for each input number, if it is a multiple of eleven or not.

Sample input:

112233
30800
2937
323455693
5038297
112234
0

Sample output

112233 is a multiple of 11.
30800 is a multiple of 11.
2937 is a multiple of 11.
323455693 is a multiple of 11.
5038297 is a multiple of 11.
112234 is not a multiple of 11.




#include <stdio.h>
#include <string.h>
int main() {
    char s[1001];
    while(scanf("%s", s) == 1) {
        if(strcmp(s, "0") == 0)
            break;
        int i, l = strlen(s), sum = 0;
        for(i = l-1; i >= 0; i -= 2)
            sum += s[i] - '0';
        for(i = l-2; i >= 0; i -= 2)
            sum -= s[i] - '0';
        printf("%s ", s);
        if(sum%11 == 0)
            puts("is a multiple of 11.");
        else
            puts("is not a multiple of 11.");
    }
    return 0;
}

台長: Morris
人氣(4,616) | 回應(1)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA] 10922 - 2 the 9s
此分類上一篇:[UVA] 10127 - Ones

春藥
很讚的分享~~
2020-02-20 14:02:30
是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文