알고리즘 과제를 하느라 밤을 지새고 있는데
옆 학생이 하는걸 보고 있노라니
이런 프로그램을 짜고있었다 @.@
stdin으로 문장을 입력받는데, 알파벳만 카운팅을 할것이며
입력종료조건은 라인의 첫문자가 !이면 종료
5분만에 만든코드 -_
#include<cstdio>
using namespace std;
int main(){
char buf[255];
int length[31] = {0, };
int i;
int pos, count;
while(1){
pos = count = 0;
cin.getline(buf,255);
if(buf[0]=='!')
break;
while(buf[pos]!='\0'){
if((buf[pos]>='a' && buf[pos]<='z' )||(buf[pos]>='A' && buf[pos]<='Z'))
count++;
else
{
length[count]++;
count =0;
}
pos++;
}
}
//output
for(i=0;i<31;i++){
if(length[i])
cout << "length(" << i << ") = " << length[i] << endl;
}
return 0;
}
Trackback Address :: http://blog.kfmes.com/trackback/84
