Please help. what is test case 8. so that i can verify my answers. will somebody helps me? me too.. I think here the line begins with something like: andro.... or ndroS.... Try this test : tTTTTT ans:60 Edited by author 27.06.2011 02:14 Thanks, that really helped :D Thanks for help. The problem were in checking substrings with length less then 6. Прошу помочь. Написал алгоритм на питоне, все придуманные мной примеры работают, однако шестой тест неумолим... Подскажите, где ошибка? Код прилагаю string = input() find = 'Sandro' lst = [] string = ' ' + string + ' ' def counter(indexInFind, indexInString): global string global find summ = 0 index = 0 temp='' for i in range(indexInString - indexInFind, indexInString - indexInFind + 6): if string[i] == ' ': return # if string[i] != find[index]: summ += 5 index += 1 temp += string[i] return summ if temp.find('S') != -1 or temp.find('s') != -1 else summ+5 for i in range(len(string)): strfind = find.find(string[i]) if strfind != -1: lst.append(counter(strfind, i)) print(min(lst) if len(lst) != 0 else 35) Edited by author 19.12.2018 01:29 Edited by author 19.12.2018 01:29 Edited by author 19.12.2018 01:31 I have true answers on all tests with this forum, but have WA#9! Help me! This is my code: #include <iostream> using namespace std; int main() { char str[201]; int c = 0; int cmax = 0; int index = 0; const char S[7] = {'S','a','n','d','r','o','\n'}; gets(str); for(int i=0;i<strlen(str)-5;i++) { if(str[i]=='S') c+=2; if(str[i]=='s') c++; if(str[i+1]=='a') c+=2; if(str[i+1]=='A') c++; if(str[i+2]=='n') c+=2; if(str[i+2]=='N') c++; if(str[i+3]=='d') c+=2; if(str[i+3]=='D') c++; if(str[i+4]=='r') c+=2; if(str[i+4]=='R') c++; if(str[i+5]=='o') c+=2; if(str[i+5]=='O') c++; if(c>cmax) { cmax = c; index = i; } } c = 0; if((str[index]=='s')||((int(str[index])<=90)&&(str[index]!='S'))) c++; else if(str[index]!='S') c+=2;
if((str[index+1]=='A')||((int(str[index+1])>90)&&(str[index+1]!='a'))) c++; else if(str[index+1]!='a') c+=2;
if((str[index+2]=='N')||((int(str[index+2])>90)&&(str[index+2]!='n'))) c++; else if(str[index+2]!='n') c+=2;
if((str[index+3]=='D')||((int(str[index+3])>90)&&(str[index+3]!='d'))) c++; else if(str[index+3]!='d') c+=2;
if((str[index+4]=='R')||((int(str[index+4])>90)&&(str[index+4]!='r'))) c++; else if(str[index+4]!='r') c+=2;
if((str[index+5]=='O')||((int(str[index+5])>90)&&(str[index+5]!='o'))) c++; else if(str[index+5]!='o') c+=2; cout<<c*5<<endl; return 0; } Try the test: sssssssssssssssssssssssssssssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaannnnnnnnnnnnnnnnnnnnnnnnnndroooooooooooooo Your program's answer is 30. The right answer is 15. ( 1.sssssssssssssssssssssssssssssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaannnnnnnnnnnnnnnnnnnnnnnsnndroooooooooooooo 2.sssssssssssssssssssssssssssssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaannnnnnnnnnnnnnnnnnnnnnnsandroooooooooooooo 3.sssssssssssssssssssssssssssssssssssssssssssssssaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaannnnnnnnnnnnnnnnnnnnnnnSandroooooooooooooo ) The wierd thing is that for "mmndro" the answer is right. :D I got the bug. In the first for, your c is always increasing, so your cmax will be wrong. Put "c=0" before to close the for. It should work perfect now. #include<iostream> #include<string> using namespace std; int main () { string s; cin>>s; int max=0,i=0,index=0,a=0,p=0; for (i=0; i<s.size()-5; i++) { if(s[i]>'a' && s[i]<='z') p--; if(s[i]=='S') p+=2; if(s[i+1]=='a') p+=2; if(s[i+1]>='A' && s[i+1]<='Z') p--; if(s[i+2]=='n') p+=2; if(s[i+2]>='A' && s[i+2]<='Z') p--; if(s[i+3]=='d') p+=2; if(s[i+3]>='A' && s[i+3]<='Z') p--; if(s[i+4]=='r') p+=2; if(s[i+4]>='A' && s[i+4]<='Z') p--; if(s[i+5]=='o') p+=2; if(s[i+5]>='A' && s[i+5]<='Z') p--; if (p>max) { max=p; index=i; } p=0; } i=index; if (s[i]!='S' && s[i]>='A' && s[i]<='Z' || s[i]=='s') a+=5; else if (s[i]!='S' && s[i]>='a' && s[i]<='z') a+=10; if (s[i+1]!='a' && s[i+1]>='a' && s[i+1]<='z' || s[i+1]=='A') a+=5; else if (s[i+1]!='a' && s[i+1]>='A' && s[i+1]<='Z') a+=10; if (s[i+2]!='n' && s[i+2]>='a' && s[i+2]<='z' || s[i+2]=='N') a+=5; else if (s[i+2]!='n' && s[i+2]>='A' && s[i+2]<='Z') a+=10; if (s[i+3]!='d' && s[i+3]>='a' && s[i+3]<='z' || s[i+3]=='D') a+=5; else if (s[i+3]!='d' && s[i+3]>='A' && s[i+3]<='Z') a+=10; if (s[i+4]!='r' && s[i+4]>='a' && s[i+4]<='z' || s[i+4]=='R') a+=5; else if (s[i+4]!='r' && s[i+4]>='A' && s[i+4]<='Z') a+=10; if (s[i+5]!='o' && s[i+5]>='a' && s[i+5]<='z' || s[i+5]=='O') a+=5; else if (s[i+5]!='o' && s[i+5]>='A' && s[i+5]<='Z') a+=10; cout<<a<<endl; return 0; } Edited by author 30.12.2014 18:40 Edited by author 03.01.2015 17:13 Edited by author 03.01.2015 17:13 Try Dandro (must be 5, feeling like ur programm returns 10) #include<iostream> #include<list> using namespace std; bool in_the_range(char a) { if (a >= 'a'&&a <= 'z') { return true; } else { return false; } } int chance_one_symb(char in_symbol, char out_sybmbol) { if ((in_the_range(in_symbol) && in_the_range(out_sybmbol)) || !(in_the_range(in_symbol)) && !(in_the_range(out_sybmbol))) { if (in_symbol == out_sybmbol) { return 0; } else { return 5; } } else { if (((int)in_symbol + 32) == out_sybmbol || ((int)in_symbol - 32) == out_sybmbol) { return 5; } else { return 10; } }
} int main() { char str[200] = { NULL }; const char word[6] = { 'S', 'a', 'n', 'd', 'r', 'o' }; int final_cost = 60, temp_cost = 0; cin.get(str, 200); list<char> temp; list<char>::iterator ptr; for (size_t i = 0; i < 6; i++) { temp.push_back(str[i]); } int j = 0; for (size_t i = 6; i <= strlen(str); i++) { for (ptr=temp.begin(); ptr!=temp.end(); ptr++) { temp_cost += chance_one_symb(*ptr, word[j]); if (temp_cost>=final_cost) { break; } j++; } j = 0; if (temp_cost < final_cost) { final_cost = temp_cost; } temp_cost = 0; temp.pop_front(); temp.push_back(str[i]); } cout << final_cost; return 0; } Edited by author 14.07.2016 22:33 Seeing a similar code on other tasks previously, i can already tell the problem by intuition. Try something like <194 symbols>Sandro. I solve this problem with dp. Cool problem, similar to the Levenshtein,but with some differents. Levenshtein problem Not. This is not Levenshtein problem. It's different. first 7 tests are all strings of length 6. so if you wa 8, your program may not handle string of length > 6. Hi, guys! In the problem statement input is a string, that consists of a..z or A..Z. Let me guess, Test 7 has some other chars ? If so, please, correct prom statement with this note. 4 my submissions were with WA#7 until I added char check Test 7 consists of characters a..z and A..Z only. I had the same situation as topic starter. Maybe there is '\n' at the end of the test #7. Can somebody help me? What's the problem? program BgrSandro; type t = 'A'..'Z'; const andro = 'andro'; lowcs=['a'..'z']; var i,j,c,min: integer; s: string; set1: set of t; Begin set1:=['A'..'Z'] - ['A','N','D','R','O']; readln(s); min:=20; for i:=1 to (Length(s)-5) do begin c:=0; if (s[i]<>'S') then begin inc(c); if (s[i]<>'s') and (s[i] in lowcs) then inc(c) end; for j:=1 to 5 do begin if (s[i+j]<>andro[j]) then begin inc(c); if (s[i+j] in set1) then inc(c) end end; if (c<min) then min:=c; end; writeln(min*5); end. Edited by author 21.04.2012 03:52 Edited by author 27.06.2011 13:51 Apply the GOOD JOB for College ACMers to Make Large Money and Become a Millionaire Hello, We need large no. of dedicated and hard working ACMers. The payment is good so we need ACMers to be efficient. All you have to do to get the job is to sign up at our websites. The link of our websites are given below. http://www.PaisaLive.com/register.asp?3556638-4847933 After the registration, a confirmation email will be sent to your specified email address. Please click on the link inside the confirmation email to activate your account and recieve ACM work instantly. For any other queries you can mail the administrator. Miss Juliet Admin paisalive.com #include <cstdio> #include <cstring> char s1[10] = "Sandro", s2[10] = "sANDRO", l[205], n, a[10] = "Aaaaaa" , b[10] = "Zzzzzz"; int min = 60000; int main(){ scanf("%s", &l); n = strlen(l) - 5;
for ( int i = 0; i < n; i++ ){ int t = 0; for ( int j = 0; j < 6; j++ ){ if ( l[i+j] != s1[j] ){ if (!( l[i+j] == s2[j] || ( l[i+j] >= a[j] && l[i+j] <= b[j] ) )) t += 1; ++t; } } if ( t < min ) min = t; } printf("%d", min*5); scanf("\n"); return 0; } Edited by author 03.12.2011 02:02 Edited by author 03.12.2011 02:02 |
|