who has this in russian or it will be better if somebody help me. thanks What you should consider is that, there will be some extra spaces at the end of ONE line. And then you'll get AC easily. #include <fstream> #include <stdio.h> #include <iostream> #include <string> using namespace std; int n; string S; int arr[1010] = {0}; char s[1010]; int main () { //freopen ("a.in", "r", stdin); //freopen ("a.out", "w", stdout); int i, j, k, t, sum; int tsum; scanf ("%d", &n); i = 0; S = ""; char c; while (scanf ("%c", &c) == 1) { //cin>>S; //cout<<i<<" "; if (c == '\n' && S != "") { //S = ""; /*for (j = 0; s[j] > 0; ++j) { if (s[j] == '0' || s[j] == '1') { S += s[j]; } }*/ if (i > 0) { cout<<endl; } ++i; sum = 0; tsum = 0; if (S.length() == n) { for (j = 0; j < n; ++j) { if (S[j] == '1') { sum += (j+1); } } sum %= (n+1); if (sum == 0) { cout<<S; S = ""; } else { S[sum-1] = '0'; //S = ""; cout<<S; S = ""; } } else if (S.length() > n) { t = 0; for (j = 0; j < S.length(); ++j) { if (S[j] == '1') { sum += (j+1); ++t; } arr[j] = sum%(n+1); } sum %= (n+1); /*for (j = S.length()-1; j >= 0; --j) { if (S[j] == '1') { tsum += (j+1); } arr[j][1] = tsum%(n+1); }*/ if ((sum+n+1-t)%(n+1) == 0) { S = S.substr (1, n); cout<<S; S = ""; continue; } t = 0; tsum = 0; for (j = S.length()-1; j > 0; --j) { if ((tsum-t+arr[j-1])%(n+1) == 0) { for (k = 0; k < j; ++k) { cout<<S[k]; } for (k = j+1; k < S.length(); ++k) { cout<<S[k]; } //cout<<endl; //continue; S = ""; break; } if (S[j] == '1') { ++t; tsum += (j+1); } } } else { sum = 0, tsum = 0, t = 0; int add; for (j = 0; j < S.length(); ++j) { if (S[j] == '1') { sum += (j+1); } arr[j] = sum%(n+1); } sum %= (n+1); //arr[n-1] = sum; if (sum == 0) { cout<<S<<0; S = ""; continue; } else if ((sum+n)%(n+1) == 0) { cout<<S<<1; S = ""; continue; } for (j = S.length()-1; j >= 0; --j) { if ((arr[j]+tsum+t)%(n+1) == 0) { for (k = 0; k <= j; ++k) { cout<<S[k]; } cout<<0; for (k = j+1; k < S.length(); ++k) { cout<<S[k]; } //cout<<endl; S = ""; break; } if ((arr[j]+tsum+t+j+1)%(n+1) == 0) { for (k = 0; k <= j; ++k) { cout<<S[k]; } cout<<1; for (k = j+1; k < S.length(); ++k) { cout<<S[k]; } S = ""; //cout<<endl; break; } if (S[j] == '1') { ++t; tsum += (j+1); } } } S = ""; } else { if (c == '0' || c == '1') { S += c; } } } return 0; } For example program must work some: 4 <INPUT 0000 <INPUT 0000 >OUTPUT 011 <INPUT 0110 >OUTPUT 1011 <INPUT 1001 >OUTPUT 11011<INPUT 1111 >OUTPUT using EOF allways in INPUT Can you give me some tests? Edited by author 16.03.2007 06:48 Edited by author 16.03.2007 19:51 My WA Reason was the extra line break at the end of output! Be Careful!!! how did you found out the reason? My solution take WA in Test # 1 If someone can help me please, write is what my mistake. code: [code deleted] Edited by moderator 13.02.2007 20:49 [code deleted] Sorry for 4th rule violation, but I see no other way possible ;) :) Edited by author 11.02.2007 08:40 Edited by moderator 13.02.2007 20:49 Giv my please Test #1? Can I not it is correct data read. HELP PLEASE??? ANYBODY??? I have 20 WA the test #1. HELP MY PLEASE. PLEASE. My Code. [code deleted] Edited by moderator 02.01.2007 18:52 I also got WA#1 and i dont know the reason why i got it :'( I'm also constantly receiving WA#1. Can't imagine what is wrong. Any ideas, any tricky tests would be great. JIeHuH*CCCP, if you find out, tell me what was your WA#1 reason, please. For example: 4 1010 My question is same as above. "At least" or exactly? Such test is wrong. There are no "correct" words that look like that after one of possible changes made. There is at least one solution ALWAYS. In statement was written: "3. A symbol (0 or 1) is inserted at any position." How many symbols can be inserted at any position? Answer me, please. How many modification may occur with any word? Only one of three or three modifications together? I think 'a symbol' is just only one I am getting trouble with test #3 "A symbol..." - i think it means, that the symb. is only one... Because not "Symbols..." PS: can't pass test #1 There is nothing else in the file, except maybe for some extra spaces or line breaks. What das it mean? Maybe? #input 1 4 000 000 -------- OR #input 2 6 000 00 111111 000111 Who solve this problem please tell how read input. I use i=scanf("%s",str1); if(i==EOF){ size=1; return ; } //while size >1 But always get WA1. Sorry for my English. PART of my AC source: ===================== char *in; void delete_spaces (void) { int i; for (i = 0; isdigit(in[i]); i++); in[i] = 0; } int main (void) { scanf ("%i", &N); in = new char[N + 2]; gets (in); while (gets (in)) { delete_spaces (); // decoding... outputting... } return 0; } PART of my AC source: int main( void ) { scanf("%d", &N); while (scanf("%s", S) == 1) { ... } return 0; } PS: I write using C but C++ also compile it. I am really depressed. scanf("%d",&N); while (scanf("%s", str) == 1) { delete_spaces (); correct(); out(); } ALWAYS get WA1. and printf("0000\n0110\n1001\n1111\n"); return 0; too incorrect Who has test №1? Please give. lifanov@mail.ru Maybe first test is not the same as in sample input... Maybe something wrong with your decoding function? Edited by author 02.04.2005 19:27 input string: 001 1 000 111 if you use scanf("%s",&str); str="001" if you use gets(str); str="001 1 000 111" So... ;) I think this: ... int n,i,j; char t[1000],word[1000]; scanf("%i",&n); gets(t); while (!feof(stdin)) {gets(t); j=0; for (i=0;i<strlen(t);i++) if (isdigit(t[i])!=0) {word[j]=t[i]; j++;} word[j]='\x0'; ... } ... would be OK i'm confusing with your "delete_spaces" function. void delete_spaces (void) { int i; for (i = 0; isdigit(in[i]); i++); in[i] = 0; } All i got from this source is... "change the 1st ' ' from the left into '0'." & "if ' ' is not found in the line -> add '0' to the right." So, I don't think "delete_spaces" is a correct function. I know that it is stupid to read all strings and then process them, instead of reading one - processing it, reading next, processing it and so on. But I coded as wrote before(read all and then solve) I created int r[1024][1024], because in the task there is written that "There are no more than 1000 words in the file", and size of each is no more than 1001(initially is 1000, but with one inserted symbol...). I got Crash(access violation), I guessed that maybe I addressed inaccessible memory. I updated my code and replaced it by this: char r[1024][1024]; string s; cin>>n; m = 0; cin>>s; while (!(cin.eof())){ if (m > 1000) continue; if (s.size()>n+1) return; if (s.size()<n-1) return; strcpy(r[m++],s.c_str()); len[m-1] = strlen(r[m-1]); cin>>s; } and got TL test 3. So it was, I think, because of if (m > 1000) continue; then I made int r[3000][1024] and got AC )) why? maybe there is more than 1000 words in the file? It,s unfair! One year I have been thinking that "I too stupid to solve this problem" Firstly we are supplied with onest information and immediately have Ac simply increased sizez of arrays. I think there are not fewer than 10-15 such problem's statements with errors. How do I number the positions? [code deleted] Could anyone help me? Edited by moderator 08.07.2006 22:33 I have WA for test#1 but i verified the problem with all possible words of lengths between 2 and 20 and it returned correct answers. Also I have taken into account the possibility of entering words like: 0000 0001 100 101 or 00 0 0 10 0 but it still says WA. email : sraduvictor@yahoo.com I tried to leave main cycle when the input is null-string, but I got "Output Limit Exceeded". More over, the problem says that there may be some line breaks. So what the point? Use feof(stdin) or cin.eof() 1. while (scanf(..) != EOF) 2. while (cin.peek() != EOF) I output the answer for a consecutive binary word right after the input... What is "Output Limit" ? EXAMPLE: VAR I:INTEGER; BEGIN WHILE I=0 DO WRITE(I); END. I think my program is correct. sum = 0; fl = 0; for (i = len; i > 0; i--) { if (s[i] == '1') { sum += i; fp[i] = ++count; } else fp[i] = count; } d = sum%(n+1); p = n+1-d; if (d == 0) printf("%s0\n", s); else if (d == 1) printf("%s1\n", s); else if (p <= count) { for (i = 1; i <= len; i++) { if (fl == 0 && fp[i] == p) { printf("0"); fl = 1; } printf("%c", s[i]); } } else { for (i = 1; i <= len; i++) { if (fl == 0 && fp[i]+i == p) { printf("1"); fl = 1; } printf("%c", s[i]); } } |
|