formatter.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include<cstdio>
  2. #include<cstdlib>
  3. #include<cstring>
  4. #include<cmath>
  5. #include<algorithm>
  6. using namespace std;
  7. typedef long long LL;
  8. int main()
  9. {
  10. //freopen("1.in","r",stdin);
  11. char c,last;
  12. int nSpace=0,nR=0,first;
  13. while(1)
  14. {
  15. last=c,c=getchar();
  16. if(c==EOF)
  17. {
  18. if(last!='\n')
  19. putchar('\n');
  20. break;
  21. }
  22. else if(c!='\r'&&c!=' ')
  23. {
  24. if(c!='\n'&&first==0)
  25. {
  26. for(int j=1;j<=nSpace;++j)
  27. putchar(' ');
  28. for(int j=1;j<=nR;++j)
  29. putchar('\r');
  30. }
  31. else if(c!='\n')
  32. {
  33. for(int j=1;j<=nR;++j)
  34. putchar('\r');
  35. for(int j=1;j<=nSpace;++j)
  36. putchar(' ');
  37. }
  38. nSpace=nR=0;
  39. putchar(c);
  40. }
  41. else if(c==' ')
  42. {
  43. ++nSpace;
  44. if(nR==0)
  45. first=0;
  46. }
  47. else
  48. {
  49. ++nR;
  50. if(nSpace==0)
  51. first=1;
  52. }
  53. }
  54. return 0;
  55. }