Posted on 2009-08-29 04:26
Uriel 阅读(328)
评论(0) 编辑 收藏 引用 所属分类:
POJ
开始看到一以为写起来会很麻烦,没想到堆了几个库函数就解决了
不过,这反映出自己对C语言库函数是非常的不熟悉。。。
算是水题。。但是还是学到一些东西。。写下来以免忘了
1.strtol
long int strtol(const char *nptr, char **endptr, int base)
/* 从一个以base为进制的字符串转为一个长整型数 */
2.itoa
char *itoa(int value, char *string, int base)
/* 从一个int型数转为base进制的数后存进string里 */
该题代码如下:(用GCC交。。用C,C++均CE。。(itoa。。))

/**//*Problem: 1546 User: Uriel
Memory: 544K Time: 0MS
Language: GCC Result: Accepted */

#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<string.h>

char *res,str[100],rsc[100];
int a,b,num,i;

int main()


{
while(scanf("%s %d %d",rsc,&a,&b)!=EOF)

{
memset(str,0x00,sizeof(str));
itoa(strtol(rsc,&res,a),str,b);
if(strlen(str)<=7)

{
for(i=0;i<strlen(str);i++)

{
if(str[i]>='a' && str[i]<='z')str[i]-=32;
}
printf("%7s\n",str);
}
else
printf("%7s\n","ERROR");
getchar();
}
return 0;
}

