http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=386
这道题目题意没看清,以为是把所有的数据一次性输入,然后一次性输出,搞得我郁闷死了。。。。其实是一组输入,一组输出。刚学习fgets()函数,所以是用字符串写的,代码不是很精简,后来在网上看到用getchar()输入字符比较简单,看来字符串还是掌握的不够好啊
#include<stdio.h>
#include<string.h>
#define N 150
char str[N][N];
int main()
{
int i,j,u,sum=0;
for(i=0;fgets(str[i],N,stdin);i++)
{
for(j=0;j<strlen(str[i])-1;j++)
{
if(str[i][j]=='!')
{
printf("\n");
sum=0;
}
if(str[i][j]>='0'&&str[i][j]<='9')
{
sum+=str[i][j]-'0';
}
if((str[i][j]>='A'&&str[i][j]<='Z')||str[i][j]=='*')
{
for(u=0;u<sum;u++)
putchar(str[i][j]);
sum=0;
}
if(str[i][j]=='b')
{
for(u=0;u<sum;u++)
putchar(' ');
sum=0;
}
}
printf("\n");//每一行字符串处理完后都要换行
}
return 0;
}
#include <stdio.h>
#include <ctype.h>
//ctype.h中定义的isupper,islower,isalpha,isdigit,isprint(判断是否为可打印字符)等函数可以判断字符的属性
//toupper,tolower等工具可以转换大小写
int main(void)
{
char ch;
int i, count = 0;
while ((ch = getchar()) != EOF) {
if (isdigit(ch)) {
count += ch - '0';
continue;
} else if (ch == '!' || ch == '\n')
putchar('\n');
else {
if (ch == 'b')
ch = ' ';
for (i=0; i<count; ++i)
putchar(ch);
count = 0;
}
}
return 0;
}