Advertisement
Guest User

Untitled

a guest
May 24th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.50 KB | None | 0 0
  1. ----Длина текста----
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. int main() {
  6. char a[10000];
  7. FILE* fp;
  8. fp = fopen("input.txt", "r");
  9. int count = 0;
  10. while (!feof (fp)) {
  11. if (fgets(a, 9999, fp)) count+=strlen(a);
  12. }
  13. printf("%i", count);
  14. return 0;
  15. }
  16. -----Простая замена-----
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. int main() {
  21. char a[10000];
  22. gets(a);
  23. for (int i=0;i<strlen(a);++i)
  24. {
  25. if (a[i]=='A'){
  26. a[i]='b';
  27. continue;
  28. }
  29. if (a[i]=='a'){
  30. a[i]='B';
  31. continue;
  32. }
  33. if (a[i]=='B'){
  34. a[i]='a';
  35. continue;
  36. }
  37. if (a[i]=='b'){
  38. a[i]='A';
  39. continue;
  40. }
  41. }
  42. printf("%s",a );
  43. return 0;
  44. }
  45. ------Подсчет числа способов 2-------
  46. #include <stdlib.h>
  47. #include <stdio.h>
  48. int main() {
  49. int count=0;
  50. char a[1000];
  51. scanf("%[^\n]s",a);
  52. int i=0;
  53. int fl_slovo=0;
  54. while(a[i]!='\0' && a[i]!='\n')
  55. {
  56. if(a[i]!=' ' )
  57. {
  58. if (fl_slovo==0)
  59. {
  60. fl_slovo=1;
  61. count++;
  62. }
  63. }
  64. else{
  65. fl_slovo=0;
  66. }
  67. i++;
  68. }
  69. printf("%i",count);
  70. return 0;
  71. }
  72. -------Очистка строки--------
  73. 1)
  74. #include <stdio.h>
  75. #include <stdlib.h>
  76. int main() {
  77. char a[1000];
  78. gets(a);
  79. int i = 0;
  80. int fl = 0;
  81. int len = 0;
  82. while (a[i] != '\0')
  83. {
  84. len++;
  85. i++;
  86. }
  87. i = 0;
  88. for (int i = 0; i < len; ++i)
  89. {
  90. if (a[i] == ' ')
  91. {
  92. int k = i + 1;
  93. while (a[k] == ' ')
  94. {
  95. for (int j = k; j < len; ++j)
  96. {
  97. a[j] = a[j + 1];
  98. }
  99. a[len - 1] = '\0';
  100. len--;
  101. }
  102. }
  103. }
  104. if (a[0] == ' ')
  105. {
  106. for (int j = 0; j < len; ++j)
  107. {
  108. a[j] = a[j + 1];
  109. }
  110. }
  111. if (a[len - 1] == ' ')
  112. {
  113. a[len - 1] = '\0';
  114. len--;
  115. }
  116. printf("%s", a);
  117. return 0;
  118. }
  119. 2)
  120. #include <stdio.h>
  121. #include <stdlib.h>
  122. #include <string.h>
  123. int main() {
  124. char a[1000];
  125. char buffer[1000];
  126. gets(a);
  127. int len = strlen(a);
  128. int fl = 1;
  129. int iter = 0;
  130. for (int i = 0; i < len; ++i)
  131. {
  132. if (a[i] == ' ')
  133. {
  134. fl = 1;
  135. continue;
  136. }
  137. if (fl == 1)
  138. {
  139. int flag_arab = 0;
  140. int count = 0;
  141. for (int j = i; a[j] != ' ' && j < len; ++j)
  142. {
  143. count++;
  144. if (a[j] == '1' || a[j] == '2' || a[j] == '3' || a[j] == '4' || a[j] == '5' || a[j] == '6' || a[j] == '7' || a[j] == '8' || a[j] == '9' || a[j] == '0')
  145. {
  146. flag_arab = 1;
  147. }
  148. }
  149. if (flag_arab != 1)
  150. {
  151. for (int j = i; j < count + i; j++)
  152. {
  153. buffer[iter] = a[j];
  154. iter++;
  155. }
  156. buffer[iter] = ' ';
  157. iter++;
  158. buffer[iter] = '\0';
  159. }
  160. fl = 0;
  161. }
  162. }
  163. if (buffer[iter - 1] == ' ')
  164. {
  165. buffer[iter - 1] = '\0';
  166. iter--;
  167. }
  168. printf("%s", buffer );
  169. return 0;
  170. }
  171. 3)
  172. #include <stdio.h>
  173. #include <stdlib.h>
  174. #include <string.h>
  175. #include <ctype.h>
  176. int main() {
  177. char a[1000];
  178. char buffer[1000];
  179. gets(a);
  180. int len = strlen(a);
  181. int fl = 1;
  182. int iter = 0;
  183. for (int i = 0; i < len; ++i)
  184. {
  185. if (a[i] == ' ')
  186. {
  187. fl = 1;
  188. continue;
  189. }
  190. if (fl == 1)
  191. {
  192. int flag_arab = 0;
  193. int count = 0;
  194. for (int j = i; a[j] != ' ' && j < len; ++j)
  195. {
  196. count++;
  197. if (!isalnum(a[j]) && a[j]!='–')
  198. {
  199. flag_arab = 1;
  200. }
  201. }
  202. if (flag_arab != 1)
  203. {
  204. for (int j = i; j < len && j < count + i; j++)
  205. {
  206. buffer[iter] = a[j];
  207. iter++;
  208. }
  209. buffer[iter] = ' ';
  210. iter++;
  211. buffer[iter] = '\0';
  212. }
  213. fl = 0;
  214. }
  215. }
  216. if (buffer[iter - 1] == ' ')
  217. {
  218. buffer[iter - 1] = '\0';
  219. iter--;
  220. }
  221. printf("%s", buffer );
  222. return 0;
  223. }
  224. --__------- Выжимки----------
  225. 1)Числовая
  226. #include <stdio.h>
  227. #include <stdlib.h>
  228. #include <string.h>
  229. #include <ctype.h>
  230. int comp(const int *i,const int *j)
  231. {
  232. return *i-*j;
  233. }
  234. int main() {
  235. char a[10000];
  236. char buffer[10000];
  237. int chisla[1000];
  238. int counter=0;
  239. gets(a);
  240. int len = strlen(a);
  241. int fl = 1;
  242. int iter = 0;
  243. for (int i = 0; i < len; ++i)
  244. {
  245. if (a[i] == ' ')
  246. {
  247. fl = 1;
  248. continue;
  249. }
  250. if (fl == 1)
  251. {
  252. int flag_arab = 0;
  253. int count = 0;
  254. for (int j = i; a[j] != ' ' && j < len; ++j)
  255. {
  256. count++;
  257. if (!isdigit(a[j]) && a[j]!='+' &&a[j]!='-')
  258. {
  259. flag_arab = 1;
  260. }
  261. }
  262. if (flag_arab != 1)
  263. {
  264. for (int j = i; j < count + i; j++)
  265. {
  266. buffer[iter] = a[j];
  267. iter++;
  268. }
  269. buffer[iter] = '\0';
  270. chisla[counter]=atoi(buffer);
  271. buffer[0]='\0';
  272. iter=0;
  273. counter++;
  274. }
  275. fl = 0;
  276. }
  277. }
  278. qsort(chisla, counter, sizeof (int), (int(*) (const void *, const void *)) comp);
  279. for(int i=0;i<counter;++i)
  280. {
  281. if(i!=counter-1){printf("%i ",chisla[i]);}
  282. else printf("%i",chisla[i]);
  283. }
  284.  
  285. return 0;
  286. }
  287. 3 Латинская)
  288. #include <stdio.h>
  289. #include <stdlib.h>
  290. #include <string.h>
  291. #include <ctype.h>
  292. int main() {
  293. char a[10001];
  294. char** chisla = (char**) calloc(10000, sizeof(char*));
  295. scanf("%[^\n]s",a);
  296. int len = strlen(a);
  297. int fl = 1;
  298. int iter = 0;
  299. int ind = 0;
  300. for (int i = 0; i < len; ++i)
  301. {
  302. if (isspace(a[i]))
  303. {
  304. fl = 1;
  305. continue;
  306. }
  307. if (fl == 1)
  308. {
  309. int flag_arab = 0;
  310. int count = 0;
  311. for (int j = i; (!isspace(a[j])) && j < len; ++j)
  312. {
  313. count++;
  314. if (!isalpha(a[j]))
  315. {
  316. flag_arab = 1;
  317. }
  318. }
  319. if (!flag_arab)
  320. {
  321. chisla[ind] = (char*)calloc(10000, sizeof(char));
  322. for (int j = i; j < count + i; j++)
  323. {
  324. chisla[ind][iter] = a[j];
  325. iter++;
  326. }
  327. chisla[ind][iter] = '\0';
  328. ind++;
  329. iter = 0;
  330. }
  331. fl = 0;
  332. }
  333. }
  334. for (int i = 0; i < ind - 1; ++i)
  335. {
  336. for (int j = 0; j < ind - i - 1; ++j)
  337. {
  338. char buffer_one[1000];
  339. char buffer_two[1000];
  340. strcpy(buffer_one,chisla[j]);
  341. strcpy(buffer_two,chisla[j+1]);
  342. for (int s=0;s<strlen(buffer_one);++s)
  343. {
  344. buffer_one[s]=tolower(buffer_one[s]);
  345. }
  346. for (int s=0;s<strlen(buffer_two);++s)
  347. {
  348. buffer_two[s]=tolower(buffer_two[s]);
  349. }
  350. if(strcmp(buffer_one,buffer_two)>0)
  351. {
  352. char* buf = chisla[j];
  353. chisla[j]=chisla[j+1];
  354. chisla[j+1]=buf;
  355. }
  356. }
  357. }
  358. for (int i = 0; i < ind; ++i)
  359. {
  360. if (i != ind - 1) {printf("%s ", chisla[i]);}
  361. else printf("%s", chisla[i]);
  362. }
  363. return 0;
  364. }
  365. =====Простой переворот===
  366. #include <stdio.h>
  367. #include <stdlib.h>
  368. int main() {
  369. char a[1000];
  370. gets(a);
  371. int i = 0;
  372. int fl = 0;
  373. int len = 0;
  374. while (a[i] != '\0')
  375. {
  376. len++;
  377. i++;
  378. }
  379. for(int j=0;j<len*0.5;++j)
  380. {
  381. int temp=a[j];
  382. a[j]=a[len-1-j];
  383. a[len-1-j]=temp;
  384. }
  385. printf("%s", a);
  386. return 0;
  387. }
  388. ======Непростой переворот 1-2=======
  389. 1))))
  390. #include <stdio.h>
  391. #include <stdlib.h>
  392. int main() {
  393. char a[1000];
  394. char dop[100];
  395. gets(a);
  396. int i = 0;
  397. int len = 0;
  398. while (a[i] != '\0')
  399. {
  400. len++;
  401. i++;
  402. }
  403. int fl = 1;
  404. for (int j = 0; j < len; ++j)
  405. {
  406. if (a[j] == ' ')
  407. {
  408. fl = 1;
  409. continue;
  410. }
  411. if (a[j] != ' ' && fl == 1)
  412. {
  413. int count = 0;
  414. for (int o = j; a[o] != ' ' && a[o]!='\0'; ++o)
  415. {
  416. dop[count] = a[o];
  417. count++;
  418. }
  419. dop[count]='\0';
  420. for (int o = 0; o < count * 0.5; o++)
  421. {
  422. char temp = dop[o];
  423. dop[o] = dop[count - 1 - o];
  424. dop[count - 1 - o] = temp;
  425. }
  426. int f=0;
  427. for (int o = j; o < count+j; o++)
  428. {
  429. a[o] = dop[f];
  430. f++;
  431. }
  432. j+=count;
  433. dop[0]='\0';
  434. }
  435. }
  436. printf("%s", a);
  437. return 0;
  438. }
  439. 2))))))))))
  440. #include <stdio.h>
  441. #include <stdlib.h>
  442. int main() {
  443. char a[10000];
  444. char dop[10000];
  445. gets(a);
  446. int u = 0;
  447. int len = 0;
  448. while (a[u] != '\0')
  449. {
  450. len++;
  451. u++;
  452. }
  453. for (int i = 0; i < len; ++i)
  454. {
  455. if (a[i] == ' ')
  456. {
  457. int k = i + 1;
  458. while (a[k] == ' ')
  459. {
  460. for (int j = k; j < len; ++j)
  461. {
  462. a[j] = a[j + 1];
  463. }
  464. a[len - 1] = '\0';
  465. len--;
  466. }
  467. }
  468. }
  469. if (a[0] == ' ')
  470. {
  471. for (int j = 0; j < len; ++j)
  472. {
  473. a[j] = a[j + 1];
  474. }
  475. }
  476. if (a[len - 1] == ' ')
  477. {
  478. a[len - 1] = '\0';
  479. len--;
  480. }
  481. int fl = 1;
  482. for (int j = 0; j < len; ++j)
  483. {
  484. if (a[j] == ' ')
  485. {
  486. fl = 1;
  487. continue;
  488. }
  489. if (a[j] != ' ' && fl == 1)
  490. {
  491. int count = 0;
  492. for (int o = j; a[o] != ' ' && a[o]!='\0'; ++o)
  493. {
  494. dop[count] = a[o];
  495. count++;
  496. }
  497. dop[count]='\0';
  498. for (int o = 0; o < count * 0.5; o++)
  499. {
  500. char temp = dop[o];
  501. dop[o] = dop[count - 1 - o];
  502. dop[count - 1 - o] = temp;
  503. }
  504. int f=0;
  505. for (int o = j; o < count+j; o++)
  506. {
  507. a[o] = dop[f];
  508. f++;
  509. }
  510. j+=count;
  511. dop[0]='\0';
  512. }
  513. }
  514. printf("%s", a);
  515. return 0;
  516. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement