hdu1720 c++一水

第一篇博文就sb一点好了

当时看到这道题第一反应是刚学还没热乎的java的进制转换

可是貌似手头没有以非十进制读入的函数 也没有字符串转数字类型的函数

所以小纠结了一下 然后一不小心【好不小心】看到了discuss然后就呵呵了

这个问题明明小学期被助教莫名其妙地刁难过的

居然这么快就忘了【好了伤疤忘了疼

正文:

用c++流的一些神奇的功能来做

cin >> /*进制*/ >> /*变量*/;

以设定的进制去读入(就是把输入当做是这个进制的数来读入)

cout << /*进制*/ << /*变量*/;

以设定的进制去输出(把变量的值转换成这个进制的数去输出)

具体进制只有三种:oct, dec, hex(分别对应八、十、十六进制)

注意:

对于输入流 设定进制以后 如果后面的输入没有指定进制 则默认为之前设定的进制【而不是默认十进制

对于输出流同理

上代码

#include<cstdio>
#include<iostream>

using namespace std;

int main()
{
    int a, b;

    while(cin >> hex >> a >> b)
    {
        cout << a + b << endl;
    }

    return 0;
}
时间: 2024-08-06 11:33:31

hdu1720 c++一水的相关文章

数论E - Biorhythms(中国剩余定理,一水)

E - Biorhythms Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status Description Some people believe that there are three cycles in a person's life that start the day he or she is born. These three cycles are the

HDU1720 A+B Coming (16进制加法)

16进制加法 1 #include<stdio.h> 2 int main() 3 { 4 int a,b; 5 while(scanf("%x %x",&a,&b)!=EOF) 6 { 7 printf("%d\n",a+b); 8 } 9 } HDU1720 A+B Coming (16进制加法),码迷,mamicode.com

NYOJ 707 A Simple Problem(结构体排序) 睡前一水~~

链接:click here 题意: A Simple Problem 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 You know, just as the title imply, this is a simple problem. In a contest, given the team-id, solved, penalty of all the teams, tell me the champion.If the numbers of solved pr

Openjudge 1.13-23:区间内的真素数(每日一水)

总时间限制:  1000ms 内存限制:  65536kB 描述 找出正整数 M 和 N 之间(N 不小于 M)的所有真素数. 真素数的定义:如果一个正整数 P 为素数,且其反序也为素数,那么 P 就为真素数.例如,11,13 均为真素数,因为11的反序还是为11,13 的反序为 31 也为素数. 输入 输入两个数 M 和 N,空格间隔,1 <= M <= N <= 100000. 输出 按从小到大输出 M 和 N 之间(包括 M 和 N )的真素数,逗号间隔.如果之间没有真素数,则输出

poj 3100 &amp;&amp; zoj 2818 ( Root of the Problem ) (睡前一水)

链接:click here 题意: Given positive integers B and N, find an integer A such that AN is as close as possible to B. (The result A is an approximation to the Nth root of B.) Note that AN may be less than, equal to, or greater than B. .给你B和N,求个整数A使得A^n最接近B

ZOJ 2829 Beautiful Number(睡前一水)

链接:click here 题意:输出第N个能被3或者5整除的数,注意是||而不是&&. 代码: <pre name="code" class="cpp">//zoj 2829 #include <stdio.h> #include <stdlib.h> #include <iostream> #include <string.h> #include <math.h> using

ZOJ 1938 Binomial &amp;&amp;poj 2249 (Binomial Showdown )(睡前一水)

链接:click here 题意: In how many ways can you choose k elements out of n elements, not taking order into account?  Write a program to compute this number. 给你整数n和k,让你求组合数c(n,k). 代码: #include <cstdio> #include <cstring> #include <math.h> type

POJ 1321 棋盘问题 DFS 期末前水一水就好……

A - 棋盘问题 Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status Description 在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别.要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C. Input 输入含有多组测试数据. 每组数据的第一行是两个正整数,n k,

A+B Coming(hdu1720)

思考:十六进制的输入->%x,定义时用int.要变成十进制输出,直接在输出时用->%d. #include<stdio.h> int main() { int A,B; char d; while(scanf("%x%x%c",&A,&B,&d)!=EOF) { int C=A+B; printf("%d\n",C); } }