Advertisement
Ne-Biolog

Untitled

May 7th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <memory.h>
  4. #include <iterator>
  5. #include <cassert>
  6. #include <fstream>
  7. #include <iomanip>
  8. #include <cstdlib>
  9. #include <bitset>
  10. #include <vector>
  11. #include <cstdio>
  12. #include <string>
  13. #include <queue>
  14. #include <deque>
  15. #include <cmath>
  16. #include <ctime>
  17. #include <stack>
  18. #include <set>
  19. #include <map>
  20.  
  21. using namespace std;
  22.  
  23. //#define int long long
  24.  
  25. #define fi first
  26. #define se second
  27. #define pb push_back
  28. #define mp make_pair
  29. #define all(x) x.begin() , x.end()
  30.  
  31. typedef long long ll;
  32. typedef long double ld;
  33. typedef pair < ll , ll > pll;
  34. typedef pair < int , int > pii;
  35.  
  36. template < typename T >
  37. T read(){
  38. T p = 1 , x = 0;
  39. char s = getchar();
  40. while(s == ' ' || s == '\n') s = getchar();
  41. if(s == '-') p = -1 , s = getchar();
  42. while(s >= '0' && s <= '9'){
  43. x = x * 10 + s - '0';
  44. s = getchar();
  45. }
  46. return x * p;
  47. }
  48.  
  49. template < typename A , typename B >
  50. void Umax(A &a , const B &b){
  51. if(a < b)
  52. a = b;
  53. }
  54.  
  55. template < typename A , typename B >
  56. void Umin(A &a , const B &b){
  57. if(a > b){
  58. a = b;
  59. }
  60. }
  61.  
  62. ll bin_pow (ll a , ll n) {
  63. if(n == 0){
  64. return 1;
  65. }
  66. if(n % 2 == 1){
  67. ll cnt = a * bin_pow(a , n - 1);
  68. return cnt;
  69. }
  70. else {
  71. ll cnt = bin_pow(a , n / 2);
  72. return cnt * cnt;
  73. }
  74. }
  75.  
  76. const int N = (int) 2e5 + 10;
  77. const int MOD = (int) 1e9 + 7;
  78. const int INF = (int) 1e9 + 10;
  79. const ll LLINF = (ll) 1e18 + 10;
  80. const int dx [] = { 0 , 0 , 1 , -1 };
  81. const int dy [] = { 1 , -1 , 0 , 0 };
  82.  
  83. bool isLetter(char c) {
  84. if(c >= 'a' && c <= 'z') return true;
  85. if(c >= 'A' && c <= 'Z') return true;
  86. return false;
  87. }
  88.  
  89. int main ()
  90. {
  91. freopen("input.txt" , "r" , stdin);
  92. freopen("output.txt" , "w" , stdout);
  93. ios_base::sync_with_stdio(false);
  94.  
  95. int *lenOfWords = NULL;
  96. char **listOfWords = NULL;
  97. char *currWord = (char*)malloc(sizeof(char) * 100);
  98. for(int i = 0; i < 100; ++i) {
  99. currWord[i] = '!';
  100. }
  101. currWord[99] = '\0';
  102.  
  103. // cout << currWord << endl;
  104.  
  105. char ch = 'q';
  106. int numberOfWordsInFileN1 = 0;
  107.  
  108.  
  109. while(true) {
  110. if(ch == EOF) break;
  111. ch = getchar();
  112.  
  113. if(isLetter(ch)) {
  114. int currLen = 0;
  115. currWord[currLen] = ch;
  116. while(true) {
  117. ch = getchar();
  118. if(isLetter(ch)) {
  119. currLen++;
  120. currWord[currLen] = ch;
  121. } else break;
  122. }
  123.  
  124. currLen++;
  125. //currWord[currLen] = '\0';
  126. numberOfWordsInFileN1++;
  127.  
  128. lenOfWords = (int*)realloc(lenOfWords, numberOfWordsInFileN1 * sizeof(int));
  129. lenOfWords[numberOfWordsInFileN1 - 1] = currLen;
  130.  
  131. listOfWords = (char**)realloc(listOfWords, numberOfWordsInFileN1 * sizeof(char*));
  132. listOfWords[numberOfWordsInFileN1 - 1] = (char*)malloc(sizeof(char) * (currLen + 1));
  133. //listOfWords[numberOfWordsInFileN1 - 1][currLen] = '\0';
  134.  
  135. for(int i = 0; i < currLen; ++i) {
  136. listOfWords[numberOfWordsInFileN1 - 1][i] = currWord[i];
  137. }
  138. }
  139. }
  140.  
  141. for(int i = 0; i < numberOfWordsInFileN1; ++i) {
  142. cout << lenOfWords[i] << ' ';
  143. for(int j = 0; j < lenOfWords[i]; ++j) {
  144. cout << listOfWords[i][j];
  145. }
  146. cout << endl;
  147. }
  148.  
  149.  
  150.  
  151.  
  152.  
  153. return 0;
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement