zhx's submissions

问题描述

作为史上最强的刷子之一,zhx在各大oj上交了很多份代码,而且多数都AC了。
有一天,zhx想数一数他在n个oj上一共交了多少份代码。他现在已经统计出在第i个oj上,他交了ai份代码。而把它们加起来就是你的工作了。
当然zhx是一个不走寻常路的人,所以他的数字都是用B进制表示的。而他也要求你告诉他B进制的数。
但是zhx有一个恶趣味的习惯,他算加法的时候从来不进位。比如他算十进制5+6的答案是1。而且他还要求你也要按照他的方式来做加法。

输入描述

多组数据(不超过1000组)。读到文件尾。
对于每组数据,第一行是两个空格分开的正整数n和B(1≤n≤100, 2≤B≤36)
接下来n行,每行一个B进制数ai。数码是0到9和小写a到z。输入可能包含前导0,数字长度不超过200位。

输出描述

对于每组询问输出一行一个B进制数表示答案。不能包含前导0。

输入样例

2 3
2
2
1 4
233
3 16
ab
bc
cd

输出样例

1
233
14

大意:大数加法,要考虑全为零的情况

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    int n,B,i,j,maxn,flag,flag1,m;
    int s[210];
    char a[210][210];
    while(cin>>n>>B){
        m = flag = flag1 = maxn = 0;
    memset(s,0,sizeof(s));
    for(int i = 0 ; i < n ; i++)
        cin >> a[i];
    for(int i = 0 ; i < n ; i++){
            m = 0;
           if(strlen(a[i]) > maxn)
            maxn = strlen(a[i]);
           for(int j = strlen(a[i])-1;j >= 0;j--){
                if(a[i][j] >= ‘0‘ &&a[i][j] <=‘9‘){
                  s[m] += a[i][j] - ‘0‘;
                  s[m] %= B;
                }
                else {
                s[m] += a[i][j] + 10 - ‘a‘;
                s[m] %= B;
                }
                m++;
           }
    }
    for(int i = maxn - 1; i >= 0; i--){
            if(s[i] == 0 && flag == 0){
                    flag1++;
            }
            else {
                flag = 1;
               if(s[i] >= 0 && s[i] <= 9)
                printf("%d",s[i]);
               else printf("%c",s[i] - 10 + ‘a‘);
            }
    }
    if( flag1 == maxn)
        cout << ‘0‘;
    printf("\n");
    }
    return 0;
}

zhx's submissions

时间: 2024-10-13 11:29:51

zhx's submissions的相关文章

HDU 5186 zhx&#39;s submissions 模拟,细节 难度:1

http://acm.hdu.edu.cn/showproblem.php?pid=5186 题意是分别对每一位做b进制加法,但是不要进位 模拟,注意:1 去掉前置0 2 当结果为0时输出0,而不是全部去掉 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn=101; const int maxm=201; int n,b; char

HDU 5186 zhx&#39;s submissions (进制转换)

Problem Description As one of the most powerful brushes, zhx submits a lot of code on many oj and most of them got AC. One day, zhx wants to count how many submissions he made on n ojs. He knows that on the ith oj, he made ai submissions. And what yo

HDU - 5186 - zhx&#39;s submissions (大数高精度)

zhx's submissions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 540    Accepted Submission(s): 146 Problem Description As one of the most powerful brushes, zhx submits a lot of code on many o

杭电 HDU ACM 5186 zhx&#39;s submissions

zhx's submissions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1892    Accepted Submission(s): 507 Problem Description As one of the most powerful brushes, zhx submits a lot of code on many

BestCoder #33 zhx&#39;s submissions

解题报告不写了,光贴个代码..主要是注意各个符号,然后字符串的变换等等. #include <iostream> #include <stdio.h> #include <string.h> #include <vector> #include <map> #include <algorithm> #include <queue> #include <cmath> #include <bitset>

BestCoder Round #33(zhx&#39;s submissions-手速题,注意判断00和0的情况)

zhx's submissions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1459    Accepted Submission(s): 232 问题描述 作为史上最强的刷子之一,zhx在各大oj上交了很多份代码,而且多数都AC了. 有一天,zhx想数一数他在n  个oj上一共交了多少份代码.他现在已经统计出在第i  个oj上

bestcoder#33 1001 高精度模拟

bestcoder#33 1001 高精度模拟 zhx's submissions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description As one of the most powerful brushes, zhx submits a lo

Count Primes Total Accepted: 831 Total Submissions: 6167

题目来自:Leetcode https://leetcode.com/problems/count-primes/ Count Primes Total Accepted: 831 Total Submissions: 6167My Submissions Question  Solution Description: Count the number of prime numbers less than a non-negative number, n Hint: The number n c

hdu 5188 zhx and contest [ 排序 + 背包 ]

传送门 zhx and contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 145    Accepted Submission(s): 49 Problem Description As one of the most powerful brushes in the world, zhx usually takes part