no.1
#include<stdio.h> #define IN 1 // inside a word #define OUT 0 // outside a wrod //count lines,words,and characters in input void main() {int c,nl,nw,nc,state,wordslong; nl = nw = nc =0; state = OUT; while((c=getchar())!=EOF) {++nc; if(c=='\n') ++nl; if(c==' '||c=='\n'||c=='\t') state = OUT; else if(state == OUT) {state = IN; ++nw; } } printf("%d %d %d",nl,nw,nc); }
no.2
#include<stdio.h> //count digits,white space,others void main() { int c,i,j,nwhite,nother,havei=-1; int ndigit[10]; float count[100][12]; nwhite = nother = 0; for(i = 0; i<10; ++i) ndigit[i] = 0; while((c=getchar())!=EOF) if(c >= '0' && c <= '9') ++ndigit[c - '0']; else if (c == '\n' || c == '\t' || c == ' ') ++nwhite; else ++nother; for(i = 0 ; i < 100 ; i++) {for( j= 0 ; j < 12 ; j++) count[i][j] =0; } for(j = 0 ; j< 10 ; ++j) for(i = 0 ; i < ndigit[j] ; ++i) count[i][j]=1; for(i= 0 ;i < nwhite; ++i) count[i][10]=1; for(i= 0 ;i < nother; ++i) count[i][11]=1; for(i = 99 ; i >=0 ; --i) {for( j= 0 ; j < 12 ; j++) if(count[i][j] == 1) {havei=i; break; } if(havei!=-1) break; } printf("\n\n\nThis is the result:\n"); for(i = havei ; i >=0 ; --i) {for( j= 0 ; j < 12 ; j++) if(count[i][j]==0) printf("%-4c", ' '); else printf("%-4c",3); printf("\n"); } for(i=0;i<10;++i) printf("%-4d",i); printf("no nw\n"); }
no.3