<<Basic Data Types>> _HakerRank_C++_Introduction

#include <iostream>#include <cstdio>using namespace std;int main() {    // Complete the code.    int i ;    long l ;    char c ;    float f ;    double d ;            scanf("%d%ld %c %f%lf", &i, &l, &c, &f, &d);    printf("%d\n%ld\n%c\n%f\n%lf\n", i, l, c, f, d);    return 0;}

key point

scanf 中 int、long、float、double 前后的空白、换行,会被自动忽略。
scanf 中 string s、char c 前后的空白、换行,不会被忽略,需要自己比对计算,因为这些也算是字元。


Some C++ data types, their format specifiers, and their most common bit widths are as follows:

Int ("%d"): 32 Bit integerLong ("%ld"): 64 bit integerChar ("%c"): Character typeFloat ("%f"): 32 bit real valueDouble ("%lf"): 64 bit real value

Reading
To read a data type, use the following syntax:
scanf("'formatspecifier'", &val)

For example, to read a character followed by a double:
char ch;
double d;
scanf("%c %lf", &ch, &d);

For the moment, we can ignore the spacing between format specifiers.

Printing
To print a data type, use the following syntax:
printf("\formatspecifier\", val)

For example, to print a character followed by a double:
char ch = 'd';
double d = 234.432;
printf("%c %lf", ch, d);

Note: You can also use cin and cout instead of scanf and printf; however, if you are taking a million numbers as input and printing a million lines, it is faster to use scanf and printf.


Input Format
Input consists of the following space-separated values: int, long, char, float, and double, respectively.

Output Format
Print each element on a new line in the same order it was received as input. Note that the floating point value should be correct up to 3 decimal places and the double to 9 decimal places.

Sample Input
3 12345678912345 a 334.23 14049.30493

Sample Output
3
12345678912345
a
334.230
14049.304930000

Explanation
Print int 3,
followed by long 12345678912345,
followed by char a,
followed by float 334.230,
followed by double 14049.304930000.


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章