hdu ACM Steps 1.2.3 A+B Coming

模拟题。

16进制转化为10进制相加。toupper函数为小写转换为大写,isalpha函数判断是否为字母。

#include<cstdio>
#include<cstring>
#include<cctype>
using namespace std;
const int maxn = 100 + 10;
const int base = 16;

char s[5][maxn];
int a,b;

int trans(int m) {
    int ans=0,n=strlen(s[m]);
    for(int i=0;i<n;i++) {
        if(isalpha(s[m][i])) {
            s[m][i]=toupper(s[m][i]);
            ans+=(s[m][i]-‘A‘+10);
        }
        else ans+=(s[m][i]-‘0‘);
        ans*=base;
    }
    ans/=base;
    return ans;
}

int main() {
    while(scanf("%s",s[1])!=EOF) {
        scanf("%s",s[2]);
        a=trans(1);
        b=trans(2);
        printf("%d\n",a+b);
    }
    return 0;
}
时间: 2024-10-09 20:58:01

hdu ACM Steps 1.2.3 A+B Coming的相关文章

hdu ACM Steps 1.2.8 Balloon Comes!

水题 #include<cstdio> char s[10]; int T,a,b,res; int main() { scanf("%d",&T); while(T--) { scanf("%s%d%d",s,&a,&b); switch (s[0]) { case '+' : printf("%d\n",a+b); break; case '-' : printf("%d\n",a-b)

hdu ACM Steps 1.3.1 第二小整数

水题. 我还以为是快速选择,但快排直接就过了. #include<cstdio> #include<algorithm> using namespace std; const int maxn = 500000 + 10; int a[maxn]; int T,n; int main() { scanf("%d",&T); while(T--) { scanf("%d",&n); for(int i=1;i<=n;i++

hdu ACM Steps 1.2.5 find your present (2)

基础题.异或. 这道题很简单.但一开始我并没有想到O(n)的算法,然后排序tle了一发. 后来一直在想怎么使得俩个相同数互相"抵消"掉,灵机一动,发现这是异或. #include<cstdio> #include<algorithm> using namespace std; const int maxn = 100000 + 10; int a,n,ans; int main() { while(scanf("%d",&n) &am

hdu ACM Steps 1.2.4 Box of Bricks

模拟题. 题意为把高度不同的砖头堆变成高度相同的砖头堆最少需要移动几次. 想想就知道,要把每个砖头堆变成平均高度砖头堆最少需要移动的块数就是俩者的差值. 把所有差值都加起来以后要除以2,因为移动一块砖头对俩个砖头堆有影响. #include<cstdio> #include<cmath> const int maxn = 100 + 10; int a[maxn],n,s,h,ans,kase; int main() { while(scanf("%d",&am

HDU ACM 1103 Flo&#39;s Restaurant

分析:借助STL的min_element实现.每次更新最先被占用的桌子,具体见注释. #include<iostream> #include<algorithm> using namespace std; int main() { int A,B,C; char s[10]; int a[102],b[102],c[102]; int curtime,count,ans; int *p; //桌子最先空闲时间 while(cin>>A>>B>>C

hdu acm 1425 sort(哈希表思想)

sort Time Limit: 6000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25803    Accepted Submission(s): 7764 Problem Description 给你n个整数,请按从大到小的顺序输出其中前m大的数. Input 每组测试数据有两行,第一行有两个数n,m(0<n,m<1000000),第二行包含n个各不相同,且

HDU ACM 1005 Number Sequence

Number Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 119732    Accepted Submission(s): 29072 Problem Description A number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A

hdu acm 1166 敌兵布阵 (线段树)

敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 37903    Accepted Submission(s): 15985 Problem Description C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务

HDU ACM 1025 Constructing Roads In JGShining&amp;#39;s Kingdom-&amp;gt;二分求解LIS+O(NlogN)

#include<iostream> using namespace std; //BFS+优先队列(打印路径) #define N 500005 int c[N]; int dp[N]; //dp[i]保存的是长度为i的最长不降子序列的最小尾元素 int BS(int n,int x) //二分查找下标,当x比全部元素小时下标为1,比全部元素大时下标为n+1. { int low,high,mid; low=1,high=n; while(low<=high) { mid=(low+h