madzik4113

sztangret I termin zadanie 2

Jan 29th, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <conio.h>
  4. #include <string>
  5. #include <cstdlib>
  6. #include <fstream>
  7. /* run this program using the console pauser or add your own getch, system("pause") or input loop */
  8. using namespace std;
  9. int main(int argc, char *argv[]) {
  10. int i,n=0,e=0,a;
  11. string ciag;
  12. ciag = "2 3 4 5 6 7 , 3 5 9";
  13.  
  14. char *tab1 = new char [ciag.length()];
  15. cout<<"Tablica znakow do przecinka: "<<endl;
  16. for (i=0;i<ciag.length();i++){
  17. if(ciag[i]==','){break;}
  18. else
  19. if(ciag[i]!=' '){
  20. tab1[n]=ciag[i];
  21. cout<<tab1[n];
  22. n++;
  23. }
  24. }
  25. cout<<endl;
  26. //okreslenie pozycji przecinka -1
  27. for (i=0;i<ciag.length();i++){
  28. if(ciag[i]==',') {
  29. a=i;
  30. }
  31. }
  32.  
  33. char *tab2 = new char [ciag.length()];
  34. cout<<"Tablica znakow od przecinka: "<<endl;
  35.  
  36. for (i=a+2;i<ciag.length();i++){
  37. if(ciag[i]!=' '){
  38. tab2[e]=ciag[i];
  39. cout<<tab2[e];
  40. e++;
  41. }
  42. }
  43.  
  44. //porownanie
  45. fstream o ("liczby.txt") ;
  46. cout<<endl;
  47. for (e=0;e<ciag.length();e++) {
  48. for (n=0;n<ciag.length();n++){
  49. if( tab1[n]== tab2[e] ){
  50. cout<<tab2[e];
  51. o<<tab2[e];
  52. }
  53. }
  54. }
  55. o.close();
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment