Error[8]: Undefined offset: 260, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

写出这个数


题目

读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字。


输入格式
每个测试输入包含 1 个测试用例,即给出自然数 n 的值。


这里保证 n 小于 10 ^100 。



输出格式
在一行内输出 n 的各位数字之和的每一位,拼音数字间有 1 空格,但一行中最后一个拼音数字后没有空格。



输入样例

1234567890987654321123456789

输出样例

yi san wu
code(C++):
//万能头文件
//#include 
#include 
#include 
#include 
using namespace std;

int main(int argc, char** argv)
{
    string n;
    //输入
    cin>>n;
    //length()计算数字长度
    int m = n.length();
    //cout<
    int sum = 0;
    string k = "";//存放获取到的单个字符
    int a[m];//存放每位数字
    
//计算sum
    for(int i=0; i<m; i++)
    {
        //cout<
        k = n[i];
        //string类对象的成员函数c_str()把string 对象转换成c中的字符串样式。


否则报错。


a[i] = atoi(k.c_str()); sum += a[i]; } //cout< int d = 0; //和是d位数 for(int i=1; sum/i > 0; i*=10) { d += 1; } //cout<<"d="< //和的每位数字,测试12345,d=2,re=1,re=5 int re; for(int i=1; i<=d; i++) { int c=pow(10,d-i); re = (sum/c)%10;//(15/10)%10=1%10=1 //(15/1)%10=5 //if判断,也可以用switch语句 if(re == 0){ cout<<"ling"; } if(re == 1){ cout<<"yi"; } if(re == 2) { cout<<"er"; } if(re == 3) { cout<<"san"; } if(re == 4) { cout<<"si"; } if(re == 5) { cout<<"wu"; } if(re == 6) { cout<<"liu"; } if(re == 7) { cout<<"qi"; } if(re == 8) { cout<<"ba"; } if(re == 9) { cout<<"jiu"; } //cout<<"i="< //cout<<"re="< if(i<d) { cout<<" "; } } return 0; }

总结 基本类型转换

https://www.cnblogs.com/xiaodangxiansheng/p/12697278.html

1、整型和浮点型之间的转换

(1)普通的强制转换

    double d_Temp = 1000;
    int i_Temp;
    i_Temp = (int)d_Temp;
    cout<

(2)使用标准的强制转换

  1. static_cast
  2. dynamic_cast
  3. const_cast
  4. reinterpret_cast
    double d_Temp;
    int i_Temp = 323;
    d_Temp = static_cast(i_Temp);
2、字符串和数字之间的转换

(1)用sprintf_s函数将数字转换成字符串

    int i_temp = 2020;
    std::string s_temp;
    char c_temp[20];
    sprintf_s(c_temp, "%d", i_temp);
    s_temp = c_temp;
    std::cout << s_temp << std::endl;

(2)用sscanf函数将字符串转换成数字

   double i_temp;
   char c_temp[20] = "15.234";
   sscanf_s(c_temp, "%lf", &i_temp);
   std::cout << i_temp << std::endl;

(3)atoi, atof, atol, atoll(C++11标准) 函数将字符串转换成int,double, long, long long 型

   std::string s_temp;
   char c_temp[20] = "1234";
   int i_temp = atoi(c_temp);
   s_temp = c_temp;
   std::string s_temp;
   char c_temp[20] = "1234.1234";
   double i_temp = atof(c_temp);
   s_temp = c_temp;

(4)strtol, strtod, strtof, strtoll,strtold 函数将字符串转换成int,double,float, long long,long double 型

   std::string s_temp;
   char c_temp[20] = "4.1234";
   double a = strtod(c_temp, nullptr);  //后面的参数是如果遇到字符串则是指向字符串的引用

(5)用to_string把数字转化成字符串

   double d_temp = 1.567;
   std::string s_temp = to_string(d_temp);
3、字符串和字符之间的转换

(1)用c_str从字符串转换char*

   string s_temp = "this is string";
   const char* c_temp;
   c_temp = s_temp.c_str();

(2)char数组转换成字符串

   string s_temp;
   char c_temp[20];
   c_temp[0] = 'H';
   c_temp[1] = 'L';
   c_temp[2] = 'L';
   c_temp[3] = 'O';
   c_temp[4] = '[+++]';
   s_temp = c_temp;
)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
pta写出这个数_C_内存溢出

pta写出这个数

pta写出这个数,第1张

写出这个数
  • 题目
  • code(C++):
  • 总结
    • 基本类型转换
      • 1、整型和浮点型之间的转换
      • 2、字符串和数字之间的转换
      • 3、字符串和字符之间的转换


题目

读入一个正整数 n,计算其各位数字之和,用汉语拼音写出和的每一位数字。


输入格式
每个测试输入包含 1 个测试用例,即给出自然数 n 的值。


这里保证 n 小于 10 ^100 。



输出格式
在一行内输出 n 的各位数字之和的每一位,拼音数字间有 1 空格,但一行中最后一个拼音数字后没有空格。



输入样例

1234567890987654321123456789

输出样例

yi san wu
code(C++):
//万能头文件
//#include 
#include 
#include 
#include 
using namespace std;

int main(int argc, char** argv)
{
    string n;
    //输入
    cin>>n;
    //length()计算数字长度
    int m = n.length();
    //cout<
    int sum = 0;
    string k = "";//存放获取到的单个字符
    int a[m];//存放每位数字
    
//计算sum
    for(int i=0; i<m; i++)
    {
        //cout<
        k = n[i];
        //string类对象的成员函数c_str()把string 对象转换成c中的字符串样式。


否则报错。


a[i] = atoi(k.c_str()); sum += a[i]; } //cout< int d = 0; //和是d位数 for(int i=1; sum/i > 0; i*=10) { d += 1; } //cout<<"d="< //和的每位数字,测试12345,d=2,re=1,re=5 int re; for(int i=1; i<=d; i++) { int c=pow(10,d-i); re = (sum/c)%10;//(15/10)%10=1%10=1 //(15/1)%10=5 //if判断,也可以用switch语句 if(re == 0){ cout<<"ling"; } if(re == 1){ cout<<"yi"; } if(re == 2) { cout<<"er"; } if(re == 3) { cout<<"san"; } if(re == 4) { cout<<"si"; } if(re == 5) { cout<<"wu"; } if(re == 6) { cout<<"liu"; } if(re == 7) { cout<<"qi"; } if(re == 8) { cout<<"ba"; } if(re == 9) { cout<<"jiu"; } //cout<<"i="< //cout<<"re="< if(i<d) { cout<<" "; } } return 0; }

总结 基本类型转换

https://www.cnblogs.com/xiaodangxiansheng/p/12697278.html

1、整型和浮点型之间的转换

(1)普通的强制转换

    double d_Temp = 1000;
    int i_Temp;
    i_Temp = (int)d_Temp;
    cout<

(2)使用标准的强制转换

  1. static_cast
  2. dynamic_cast
  3. const_cast
  4. reinterpret_cast
    double d_Temp;
    int i_Temp = 323;
    d_Temp = static_cast(i_Temp);
2、字符串和数字之间的转换

(1)用sprintf_s函数将数字转换成字符串

    int i_temp = 2020;
    std::string s_temp;
    char c_temp[20];
    sprintf_s(c_temp, "%d", i_temp);
    s_temp = c_temp;
    std::cout << s_temp << std::endl;

(2)用sscanf函数将字符串转换成数字

   double i_temp;
   char c_temp[20] = "15.234";
   sscanf_s(c_temp, "%lf", &i_temp);
   std::cout << i_temp << std::endl;

(3)atoi, atof, atol, atoll(C++11标准) 函数将字符串转换成int,double, long, long long 型

   std::string s_temp;
   char c_temp[20] = "1234";
   int i_temp = atoi(c_temp);
   s_temp = c_temp;
   std::string s_temp;
   char c_temp[20] = "1234.1234";
   double i_temp = atof(c_temp);
   s_temp = c_temp;

(4)strtol, strtod, strtof, strtoll,strtold 函数将字符串转换成int,double,float, long long,long double 型

   std::string s_temp;
   char c_temp[20] = "4.1234";
   double a = strtod(c_temp, nullptr);  //后面的参数是如果遇到字符串则是指向字符串的引用

(5)用to_string把数字转化成字符串

   double d_temp = 1.567;
   std::string s_temp = to_string(d_temp);
3、字符串和字符之间的转换

(1)用c_str从字符串转换char*

   string s_temp = "this is string";
   const char* c_temp;
   c_temp = s_temp.c_str();

(2)char数组转换成字符串

   string s_temp;
   char c_temp[20];
   c_temp[0] = 'H';
   c_temp[1] = 'L';
   c_temp[2] = 'L';
   c_temp[3] = 'O';
   c_temp[4] = '';
   s_temp = c_temp;

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/562522.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-01
下一篇 2022-04-01

发表评论

登录后才能评论

评论列表(0条)