Advertisement
Ne-Biolog

Untitled

May 8th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 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. bool stringСomparison(char *x, int sizeX, char*y, int sizeY) {
  90. if(sizeX != sizeY) return false;
  91. for(int i = 0; i < sizeX; ++i) {
  92. if(x[i] != y[i]) return false;
  93. }
  94. return true;
  95. }
  96.  
  97. void readTextFromFile(int *lenOfWords, char **listOfWords, int &numberOfWordsInFileN1) {
  98. char *currWord = (char*)malloc(sizeof(char) * 100);
  99.  
  100. char ch = 'q';
  101.  
  102. while(true) {
  103. if(ch == EOF) break;
  104. ch = getchar();
  105.  
  106. if(isLetter(ch)) {
  107. int currLen = 0;
  108. currWord[currLen] = ch;
  109. while(true) {
  110. ch = getchar();
  111. if(isLetter(ch)) {
  112. currLen++;
  113. currWord[currLen] = ch;
  114. } else break;
  115. }
  116.  
  117. currLen++;
  118. numberOfWordsInFileN1++;
  119.  
  120. lenOfWords = (int*)realloc(lenOfWords, numberOfWordsInFileN1 * sizeof(int));
  121. lenOfWords[numberOfWordsInFileN1 - 1] = currLen;
  122.  
  123. listOfWords = (char**)realloc(listOfWords, numberOfWordsInFileN1 * sizeof(char*));
  124. listOfWords[numberOfWordsInFileN1 - 1] = (char*)malloc(sizeof(char) * (currLen + 1));
  125.  
  126. for(int i = 0; i < currLen; ++i) {
  127. listOfWords[numberOfWordsInFileN1 - 1][i] = currWord[i];
  128. }
  129. }
  130. }
  131.  
  132. for(int i = 0; i < numberOfWordsInFileN1; ++i) {
  133. cout << lenOfWords[i] << ' ';
  134. for(int j = 0; j < lenOfWords[i]; ++j) {
  135. cout << listOfWords[i][j];
  136. }
  137. cout << endl;
  138. }
  139.  
  140. }
  141.  
  142. int main ()
  143. {
  144. freopen("input.txt" , "r" , stdin);
  145. freopen("output.txt" , "w" , stdout);
  146. ios_base::sync_with_stdio(false);
  147.  
  148. int *lenOfWordsInFileN1 = NULL;
  149. char **listOfWordsInFileN1 = NULL;
  150. int numberOfWordsInFileN1 = 0;
  151.  
  152. int *lenOfWordsInFileN2 = NULL;
  153. char **listOfWordsInFileN2 = NULL;
  154. int numberOfWordsInFileN2 = 0;
  155.  
  156.  
  157. readTextFromFile(lenOfWordsInFileN1, listOfWordsInFileN1, numberOfWordsInFileN1);
  158. re
  159.  
  160. return 0;
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement