g++中使用itoa错误
来源:互联网 发布:加工产品在淘宝上出售 编辑:程序博客网 时间:2024/06/05 20:52
题目
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
读入一个自然数n,计算其各位数字之和,用汉语拼音写出和的每一位数字。
输入格式:每个测试输入包含1个测试用例,即给出自然数n的值。这里保证n小于10100。
输出格式:在一行内输出n的各位数字之和的每一位,拼音数字间有1 空格,但一行中最后一个拼音数字后没有空格。
输入样例:1234567890987654321123456789输出样例:
yi san wu--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
AC代码:
#include <stdio.h>#include <string.h>#include <stdlib.h>//sprintfint fnum(char c);void change(char x);int main(){#ifdef ONLINE_JUDGE#elsefreopen("C:\\in.txt", "r", stdin);#endifchar n[110];while (scanf("%s", n) != EOF){int x;int len;len = strlen(n);int sum=0;int i;for (i=0; i<len; i++){x = fnum(n[i]);sum = sum+x;}//for//printf("%d\n", sum);char num[110];//////////////////////////////////////len = f(num, "%d", sum);//功能类似itoa:sum->num,返回字符串长度//////////////////////////////////////int j;for (j=0; j<len-1; j++){change(num[j]);printf(" ");}change(num[j]);printf("\n");}return 0;}int fnum(char c){int x;switch(c){case '0': x =0; break;case '1': x =1; break;case '2': x =2; break;case '3': x =3; break;case '4': x =4; break;case '5': x =5; break;case '6': x =6; break;case '7': x =7; break;case '8': x =8; break;case '9': x =9; break;}return x;}// 输出拼音,但无空格void change(char x){switch (x){case '0':printf("ling"); break;case '1':printf("yi"); break;case '2':printf("er"); break;case '3':printf("san"); break;case '4':printf("si"); break;case '5':printf("wu"); break;case '6':printf("liu"); break;case '7':printf("qi"); break;case '8':printf("ba"); break;case '9':printf("jiu"); break;}}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
编译错误代码:
#include <stdio.h>#include <string.h>#include <stdlib.h>//sprintfint fnum(char c);void change(char x);int main(){#ifdef ONLINE_JUDGE#elsefreopen("C:\\in.txt", "r", stdin);#endifchar n[110];while (scanf("%s", n) != EOF){int x;int len;len = strlen(n);int sum=0;int i;for (i=0; i<len; i++){x = fnum(n[i]);sum = sum+x;}//for//printf("%d\n", sum);char num[110];//////////////////////////////////////itoa(sum, num , 10);//sum->num, 10进制len = strlen(num);//////////////////////////////////////int j;for (j=0; j<len-1; j++){change(num[j]);printf(" ");}change(num[j]);printf("\n");}return 0;}int fnum(char c){int x;switch(c){case '0': x =0; break;case '1': x =1; break;case '2': x =2; break;case '3': x =3; break;case '4': x =4; break;case '5': x =5; break;case '6': x =6; break;case '7': x =7; break;case '8': x =8; break;case '9': x =9; break;}return x;}// 输出拼音,但无空格void change(char x){switch (x){case '0':printf("ling"); break;case '1':printf("yi"); break;case '2':printf("er"); break;case '3':printf("san"); break;case '4':printf("si"); break;case '5':printf("wu"); break;case '6':printf("liu"); break;case '7':printf("qi"); break;case '8':printf("ba"); break;case '9':printf("jiu"); break;}}
编译错误为:
/tmp/code.cc: In function 'int main()':/tmp/code.cc:32:21: error: 'itoa' was not declared in this scope参考资料:
http://stackoverflow.com/questions/6462938/error-itoa-was-not-declared-in-this-scope
0 0
- g++中使用itoa错误
- 使用itoa错误
- GCC中使用itoa()
- C++中itoa的使用
- itoa使用
- 关于itoa函数使用到时候犯的错误
- 关于itoa函数使用到时候犯的错误
- LR中Lr_save_string()函数和Itoa()函数的使用
- LoadRunner中Lr_save_string()函数和Itoa()函数的使用
- LoadRunner中Lr_save_string()函数和Itoa()函数的使用
- 错误使用 itoa函数 引发HEAP CORRUPTION DETECTED :after Normal block 错误
- itoa的使用
- ITOA的使用
- g++使用std::thread编译错误问题
- itoa
- itoa
- itoa
- itoa
- 图像处理——日积月累
- CXF 客户端异常 javax.xml.ws.soap.SOAPFaultException: Cannot create a secure XMLInputFactory
- (国外大学作业解答)Java assignment1
- Mac 中Command Line Tools的安装配置
- matlab中 plot函数全部功能
- g++中使用itoa错误
- 遍历文件目录
- Unity 重力感应
- firefox出现内容编码错误
- 黑马程序员--高新技术--注解
- hdu 1059 Common Subsequence动态规划
- 反汇编ipanic中的 16进制数code
- SDUTOJ 2797 电影节 -----非并查集解法和并查集解法(带压缩路径)
- HBase业务实践