Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- unsigned int N=3;
- int comp(unsigned int N){
- char *c_pole1=malloc(sizeof (char)*(N+1));
- char *c_pole2=malloc(sizeof (char)*(N+1));
- unsigned int c1_i=0;
- unsigned int c2_i=0;
- unsigned int a=0;
- int x=0; //pocet opakujicih se celku
- int p;
- int o=0; //jesli se opakuje o=1, neopakuje o=0
- for(c1_i=0; c1_i<N; c1_i++){ //(c1_i<N) ? (c1_i == N) ????????
- p=getchar();
- c_pole1[c1_i]=p;
- while((p=getchar())==EOF){
- printf("Neocekavany konec vstupu\n");
- return(0); //tady bude chybovy kod
- }
- }
- for(c2_i=0; c2_i<N; c2_i++){
- p=getchar();
- c_pole2[c2_i]=p;
- while((p=getchar())==EOF){
- printf("Neocekavany konec vstupu\n");
- return(0); //tady bude chybovy kod
- }
- }
- do{
- for(a=o; a<N; a++){
- if(c_pole1[c1_i] == c_pole2[c2_i]){
- o=1;
- }
- }
- if(o==1){
- x++;
- c_pole1[c1_i%N]=c_pole2[c2_i%N];
- for(c2_i=0; c2_i<N; c2_i++){
- p=getchar();
- c_pole2[c2_i]=p;
- while((p=getchar())==EOF){
- printf("Neocekavany konec vstupu\n");
- return(0); //tady bude chybovy kod
- }
- }
- }
- if(o==0 && x==0){
- putchar(c_pole1[0]);
- c_pole1[c1_i%N]=c_pole1[(c1_i+1)%N];
- c_pole1[c1_i%N]=c_pole2[0];
- // c_pole2[c1_i+1]=c_pole1[(c2_i)]; //"???
- c_pole2[c2_i%N]=c_pole2[(c2_i+1%N)];
- p=getchar();
- while((p=getchar())==EOF){
- printf("Neocekavany konec vstupu\n");
- return(0); //tady bude chybovy kod
- }
- c_pole2[(c2_i%N)]=p;
- }
- }
- if(o==0 && x != 0){
- putchar(x);
- for(c1_i=0; c1_i<N; c1_i++){
- putchar(c_pole1[c1_i]);
- }
- }
- }while((p=getchar()) != EOF);
- free(c_pole1);
- free(c_pole2);
- return(0);
- }
- int main()
- {
- comp(N);
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement