BestCoder #33 zhx's submissions

解题报告不写了,光贴个代码。。主要是注意各个符号,然后字符串的变换等等。

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <bitset>
using namespace std;

// 大数,内存处理
const int INF = 0x3f3f3f3f;
#define ll long long int
#define MEM(a) memset(a, 0, sizeof(a))
#define MEMM(a) memset(b, -1, sizeof(b))
#define DEB(x, n) cout << (x) << " " << (n) << endl;
#define putCR printf("\n")

const int maxn = 210;
char num[maxn];
char a[maxn], b[maxn];
int n, B;

inline int getnum(char &a)
{
    if(a >= ‘0‘ && a <= ‘9‘) return a-‘0‘;
    else return a-‘a‘+10;
}

inline char cal(char &a, char &b)
{
    int t1 = getnum(a);

    int t2 = getnum(b);
    t1 = (t1 + t2) % B;
    if(t1 < 10) return t1+‘0‘;
    else return t1-10+‘a‘;
}

// 字符串翻转
inline void trans(char *a)
{
    int len = strlen(a);
    // printf("%d", len);
    for(int i = 0; i < len/2; i++)
        swap(a[i], a[len-i-1]);
}

inline void add(char *a, char *b)
{
    int len1 = strlen(a);
    int len2 = strlen(b);
    int len, rest;
    if(len1 > len2)
    {
        len = len2;
        rest = len1;
    }
    else
    {
        len = len1;
        rest = len2;
    }

    for(int i = 0; i < len; i++)
        a[i] = cal(a[i], b[i]);
    if(rest == len1) return;
    else for(int i = len; i < len2; i++) a[i] = b[i];
}

int main()
{
#ifdef DEBUG
    freopen("input", "r", stdin);
#endif

    int len;
    while(scanf("%d%d", &n, &B)!= EOF)
    {
        memset(num, 0, sizeof(num));
        for(int i = 0; i <n ;i++)
        {
            scanf("%s", a);
            trans(a); add(num, a);
        }
        trans(num);
        len = strlen(num);
        int i;
        for(i = 0; i < len; i++)
            if(num[i] != ‘0‘) break;

        if(i == len)
            printf("0");
        else for(;i < len; i++)
            printf("%c", num[i]);
        printf("\n");
    }
    return 0;
}

BestCoder #33 zhx's submissions

时间: 2024-10-12 16:24:26

BestCoder #33 zhx's submissions的相关文章

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

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

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

zhx&#39;s submissions

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

【LeetCode】107. Binary Tree Level Order Traversal II 解题报告

转载请注明出处:http://blog.csdn.net/crazy1235/article/details/51508308 Subject 出处:https://leetcode.com/problems/binary-tree-level-order-traversal-ii/ Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to rig

LeetCode236. 二叉树的最近公共祖先

* @lc app=leetcode.cn id=236 lang=cpp * * [236] 二叉树的最近公共祖先 * * https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree/description/ * * algorithms * Medium (58.46%) * Likes:    300 * Dislikes: 0 * Total Accepted:    33.9K * Total Sub