The Euclidean algorithm is thegranddaddy
of all algorithms, because it is the oldest
nontrivial algorithm that has survived to
the present day.
<input.txt>의
내용을
output.txt에
granddaddy the is algorithmEuclidean The
oldest the is it because algorithms, all of
to survived has that algorithm nontrivial
day. present the
가 되게해야되거덩?
4 라인, 23 단어 처리
는 걍모니터에 출력해주고...
while의 부분이 저 단어 역순으로 하려고하는 부분인데
이상해 자꾸 결과 이상하게 나와 ㅠㅠ 형들 저 단어 역순으로 뽑는거어케하는지 쉬운코드좀...
strok인가 뭐이런거 안배워서 못씀 ㅠ
#include <stdio.h>
#include <string.h>
int main()
{
FILE *ifp, *ofp;
char str[100];
char *res;
int w_cnt=0;
int l_cnt=0;
int cnt = 0;
int i, j, len;
ifp=fopen("input.txt", "r");
if(ifp==NULL){
printf("입력파일 개방 실패.\n");
return 1;
}
ofp=fopen("output.txt", "w");
if(ofp==NULL){
printf("출력파일 개방 실패.\n");
return 1; }
while(1){
res=fgets(str,sizeof(str),ifp);
if(res==NULL) break;
++l_cnt;
len=strlen(str)-2;
for (i=len; i>0; i--, w_cnt++)
{
if (str[i] == ' ')
{
for (j=i+1, w_cnt--; w_cnt>0; j++, w_cnt--)
fprintf (ofp,"%c", str[j]);
fputs(" ",ofp);
++cnt;
}
else if (str[i] == str[0])
{
for (j=0; j<w_cnt; j++){
fprintf (ofp,"%c", str[j]);
}
++cnt;
}
}
}
printf("%d,%d",cnt,l_cnt);
fclose(ifp);
fclose(ofp);
return 0;
}
얼마?
걍 내가 할게 ㅇㅇ ㅠ
한줄 읽고 strtok으로 끈어서 스택에 한개씩 넣은담에 다 읽은후 한개씩 빼서 출력