fork download
  1. #include<bits/stdc++.h>
  2. //Phan thanh Nhàn
  3. using namespace std;
  4. #define MAXN 512
  5. void c4a(const char* input,const char* output){
  6. FILE* f1=fopen(input,"r"),*f2=fopen(output,"w");
  7. if(!f1||!f2) return;
  8. char tmp[MAXN];
  9. while(fgets(tmp,sizeof(tmp),f1)){//Phan thnah nhan
  10. int len=strlen(tmp);
  11. if(len>0&&tmp[len-1]=='\n')
  12. tmp[len-1]='\0';
  13. int k=strchr(tmp,' ')-tmp;
  14. tmp[k]='\0';
  15. fprintf(f2,"%s \n",tmp);
  16. }
  17. fclose(f1);
  18. fclose(f2);
  19. }
  20. void c4b(const char* input,const char* output){
  21. FILE* f1=fopen(input,"r"),*f2=fopen(output,"a");
  22. if(!f1||!f2) return;
  23. int max=0;
  24. char tmp[MAXN];char ans[MAXN];
  25. while(fgets(tmp,sizeof(tmp),f1)){
  26. int len=strlen(tmp);
  27. if(len>0&&tmp[len-1]=='\n')
  28. tmp[len-1]='\0';
  29. if(strlen(tmp)>max){
  30. max=strlen(tmp);
  31. strcpy(ans,tmp);
  32. }
  33. }
  34. fprintf(f2,"%s ",ans);
  35.  
  36. fclose(f1);fclose(f2);
  37. }
  38.  
  39.  
  40. int main(){
  41. const char* input="str_input.txt";
  42. const char* output="str_output.txt";
  43. c4a(input,output);
  44. c4b(input,output);
  45.  
  46.  
  47. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Standard output is empty