Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:用gets()处理数据,输出不是以string的格式,AC了的。各个数据间不要getchar()--这个地方卡了一会。In Reply To:用gets()处理数据,输出不是以string的格式,AC了的。各个数据间不要getchar()--这个地方卡了一会。 Posted by:xiehe at 2006-04-05 22:09:18 > 都贴没AC的。。。 > 很多都用字符串做的呀。 > 我贴个没用字符串做的吧 > 似乎方便很多 > > > #include <stdio.h> > #include <string.h> > int main() > { > int a[28]; > char temp[100]; > int i,j,k; > int mark; > int blank; > int maxn=-1; > memset(a,0,sizeof(a)); > for (i=1;i<=4;i++) > { > int t; > gets(temp); > for (j=0;j<strlen(temp);j++) > { > t=temp[j]-'A'+1; > if (temp[j]>='A' && temp[j]<='Z') > {a[t]++; > if (a[t]>=maxn) maxn=a[t]; > } > } > } > for (i=maxn;i>0;i--) > { > blank=0; > mark=0; > for (j=1;j<=26;j++) > { > if (a[j]<i) blank++; > else > { > for (k=1;k<=2*blank;k++) printf(" "); > if (mark==1) printf(" "); > printf("*"); > mark=1; > blank=0; > } > } > printf("\n"); > } > for (j=1;j<26;j++) printf("%c ",j+'A'-1); > printf("Z"); > return 0; > } 不对呀!你这代码AC不了!我这个还可以。 #include <stdio.h> #include <string.h> int main() { int i, j, k, m, max[26][2], count[26] = {0}; char ch[4][73] = {0}, s[26][300]; while (gets(ch[0])) { memset(count, 0, sizeof(count)); memset(max, 0, sizeof(max)); memset(s, 0, sizeof(s)); for (i = 0; i < 26; i++) s[i][0] = 'A'+i; for (i = 1; i < 4; i++) gets(ch[i]); for (i = 0; i < 4; i++) for (j = 0; j < strlen(ch[i]); j++) if (ch[i][j]>='A' && ch[i][j]<='Z') count[ch[i][j]-'A']++; for (m = k = 0, i = 25; i >= 0; i--) { if (count[i] > m) { m = max[k][0] = count[i]; max[k][1] = i; k++; } for (j = 1; j <= count[i]; j++) s[i][j]='*'; while (j <= m) s[i][j++] = ' '; } while (--k) { for (j = max[k][0]; j > max[k-1][0]; j--) { for (i = 0; i < max[k][1]; i++) printf("%c ", s[i][j]); printf("%c\n", s[i][j]); } } for (j = max[k][0]; j >= 0; j--) { for (i = 0; i < max[k][1]; i++) printf("%c ", s[i][j]); printf("%c\n", s[i][j]); } } //system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator