编写一个程序,输入整数 n 并打印该数字的字符数(符号除外)
Write a program that inputs an integer n and prints the number of characters (except for the sign) of the number
如何摆脱标点符号? 例如-1975
答案是 4,但我的程序将其计为 5。
#include<iostream>
#include<cstring>
using namespace std;
int main() {
string n;
cin>>n;
cout<<n.length();
}
这可能不是最优雅的解决方案,但我会做这样的事情
int returnlength(int x)
{
std::string a = std::to_string(x);
int size= 0;
a[0] == '-' ? size = a.size() - 1 : size = a.size();
return size;
}
相关文章:
- 打印数字图案
- 将数字打印成文字
- 为什么有时我输入一个整数,程序将第一个输入的数字打印成十进制数?
- 必须首先打印向量 v1 中最接近整数 x 的数字<int>
- 首先按给定顺序打印所有数字,然后使用 Array 打印所有字符和其他符号
- 我的问题是关于C++中数字和序列的重复以及如何打印它们?
- 编译器始终打印十六进制/八进制数字
- 我想使用哈希图打印非重复的数字;
- 如何在控制台上打印出带有数字 0-99 的简单数组
- 错误含义;以二进制形式打印数字
- 为什么这个程序接受整数和字母数字输入并打印它们? C++ 中的 std::string 也采用整数值吗?
- 列中打印数字时如何避免打印垃圾?
- 如何编写一个程序来打印特定基数的前N个数字
- C++ 在地板函数之后以十六进制打印数字
- C 不将重复数字打印到输出
- 阿姆斯特朗数字打印错误
- 用数字打印所有可能的组合
- 将数字打印为字符串类型的数字
- 如何以特定格式将数字打印到字符串的中间
- 如何将矢量中的数字打印到文件中