Show all threads Hide all threads Show all messages Hide all messages | Python-runtime_error | Klim Shramko | 2023. Donald is a postman | 14 Mar 2023 04:27 | 1 | Why does this code throw a runtime error? Everything is right!! from sys import stdin pocht_1 = ["A", "P", "O", "R"] pocht_2 = ["B", "M", "S"] pocht_3 = ["D", "G", "J", "K", "T", "W"] count = 0 mesto = 1 for i in sys.stdin.split("\n")[1:]: if i[0] in pocht_1: if mesto == 3: count += 2 elif mesto == 2: count += 1 mesto = 1 elif i[0] in pocht_2: if mesto == 1: count += 1 elif mesto == 3: count += 1 mesto = 2 else: if mesto == 1: count += 2 elif mesto == 2: count += 1 mesto = 3 print(count) | python ,why ?thanks!!!!!! | 水泥跑道 | 2023. Donald is a postman | 12 Mar 2020 17:49 | 1 | n=int(input()) a=[] for i in range(n): s=input() if(s[0]=="A" or s[0]=="P" or s[0]=="O" or s[0]=="R"): a.append(0) elif(s[0]=="B" or s[0]=="M" or s[0]=="S"): a.append(1) else: a.append(2) t=0 for i in range(n): if(i+1<n): t=t+abs(a[i]-a[i+1]) print(t) | C++ solution | gleb@il | 2023. Donald is a postman | 29 Nov 2019 00:31 | 1 | #include <iostream> #include <set> using namespace std; int main() { int index = 0, cnt = 0, n; set<string> a, b, c; a.insert("Alice"); a.insert("Ariel"); a.insert("Aurora"); a.insert("Peter"); a.insert("Phil"); a.insert("Olaf"); a.insert("Phoebus"); a.insert("Ralph"); a.insert("Robin"); b.insert("Bambi"); b.insert("Belle"); b.insert("Bolt"); b.insert("Mulan"); b.insert("Mowgli"); b.insert("Mickey"); b.insert("Silver"); b.insert("Simba"); b.insert("Stitch"); c.insert("Dumbo"); c.insert("Genie"); c.insert("Jiminy"); c.insert("Kuzko"); c.insert("Kida"); c.insert("Kenai"); c.insert("Tarzan"); c.insert("Tiana"); c.insert("Winnie"); cin >> n; int a1=0,b1=1,c1=2; for(int i = 0; i < n; i++) { string ask; cin >> ask; if(*a.find(ask) == ask) { cnt += abs(index - a1); index = a1; } if(*b.find(ask) == ask) { cnt += abs(index - b1); index = b1; } if(*c.find(ask) == ask) { cnt += abs(index - c1); index = c1; } } cout << cnt; } | Python Solution. | Vladislav Ershov | 2023. Donald is a postman | 21 Jul 2019 14:54 | 1 | def bin_Search(arr, val): low = 0 high = len(arr)-1 while low <= high: mid = (low + high) // 2 if val < arr[mid]: high = mid - 1 elif val > arr[mid]: low = mid + 1 else: return True else: return False first = ["Alice", "Ariel", "Aurora", "Phil", "Peter", "Olaf", "Phoebus", "Ralph", "Robin"] first.sort() second = ["Bambi", "Belle", "Bolt", "Mulan", "Mowgli", "Mickey", "Silver", "Simba", "Stitch"] second.sort() third = ["Dumbo", "Genit", "Jiminy", "Kuzko", "Kida", "Kenai", "Tarzan", "Tiana", "Winnie"] third.sort() n = int(input()) pos = 1 steps = 0 for i in range(n): name = str(input()) if bin_Search(first, name) == True: steps += pos - 1 pos = 1 elif bin_Search(second, name) == True: if (pos - 2) < 0: steps += ((pos - 2) * -1) pos = 2 else: steps += pos - 2 pos = 2 else: if (pos - 3) < 0: steps += ((pos - 3) * -1) pos = 3 else: steps += pos - 3 pos = 3 print(steps)
In this solution i used binary search | тест №6 в чем проблема? pascal | Alectros | 2023. Donald is a postman | 5 Jul 2019 20:53 | 4 | var str: string; i,kol,n,pol: integer; begin readln(n); pol:=1; kol:=0; for i:=1 to n do begin readln(str); if (str='Alice')or(str='Ariel')or(str='Aurora')or(str='Phil')or(str='Peter')or(str='Olaf')or(str='Phoebus')or(str='Ralph')or(str='Robin') then begin kol:=kol+abs(pol-1);pol:=1; end else if (str='Bembe')or(str='Belle')or(str='Bolt')or(str='Mulan')or(str='Mowgli')or(str='Mickey')or(str='Silver')or(str='Simba')or(str='Stitch') then begin kol:=kol+abs(pol-2);pol:=2; end else if (str='Dumbo')or(str='Genie')or(str='Jiminy')or(str='Kuzko')or(str='Kida')or(str='Kenai')or(str='Tarzan')or(str='Tiana')or(str='Winnie') then begin kol:=kol+abs(pol-3);pol:=3; end; end; write(kol); end. Edited by author 17.11.2016 23:36 Edited by author 17.11.2016 23:36 For me it was a type mistake in "Mickey" а все моя ошибка написал "Bembe" вместо "Bambi" | WA#3; what's wrong with my code, I am losing all my mind. :'( | Neeraj Kumar | 2023. Donald is a postman | 6 May 2019 02:26 | 3 | #include <iostream> int main(void){ char nameOfKid[8]; int noOfLetters; std::cin >> noOfLetters; std::cin.ignore( 256, '\n') ; int cur, temp, steps, newcur; newcur = 0; cur = 0; steps= 0 ; for (int i = 0 ; i < noOfLetters; ++i){
std::cin.getline(nameOfKid, 8);
temp = static_cast<int>(nameOfKid[0]); switch(temp){ case 65: case 80: case 79: case 82: newcur = 1; break; case 66: case 77: case 83: newcur = 2; break; case 68: case 71: case 74: case 75: case 84: newcur = 3; break;
} if ((newcur!=cur) && (i!=0)){ steps = steps + ((newcur>cur) ? (newcur-cur): (cur-newcur));
} cur = newcur; } std::cout << steps; return 0; } You can store first letters with their's corresponding place like that: int m[256]; m['A'] = m['P'] = m['O'] = m['R'] = 1; m['B'] = m['M'] = m['S'] = 2; m['D'] = m['G'] = m['J'] = m['K'] = m['T'] = m['W'] = 3; #include<bits/stdc++.h> using namespace std; int main(){ map<char,int>mp; mp['A'] = 1; mp['O'] = 1; mp['R'] = 1; mp['P'] = 1; mp['B'] = 2; mp['M'] = 2; mp['S'] = 2; mp['D'] = 3; mp['G'] = 3; mp['J'] = 3; mp['K'] = 3; mp['T'] = 3; mp['W'] = 3; int n,ans=0,pre=-1; string s; cin>>n; while(n--){ cin>>s; if(pre== -1){ pre = mp[s[0]]; }else{ ans += abs(mp[s[0]] - pre); pre = mp[s[0]]; } } cout<<ans<<endl; return 0; } i also got WA#3 doing in same way. | easy cpp solution | holykatty | 2023. Donald is a postman | 21 Mar 2019 23:27 | 1 | #include <iostream> #include <vector> #include <string> using namespace std; int box(char a) { switch (a) { case 'A': case 'P': case 'O': case 'R': return 1; case 'B': case 'M': case 'S': return 2; default: return 3; } } int main() { int n; cin >> n; string a; vector<char>f(n); for (int i = 0; i < n; i++) { cin >> a; f[i] = a[0]; } int steps = 0; int pos = 1; for (int i = 0; i < n; i++) { steps += abs(pos - box(f[i])); pos = box(f[i]); } cout << steps << endl;
return 0; } | Python2.7 WA#4 what problem, help please? | Salavat | 2023. Donald is a postman | 2 Oct 2018 09:27 | 2 | #! /usr/bin/env python # -*- coding: utf-8 -*- from itertools import count mailBox = {"Alice": 1, "Ariel": 1, "Aurora": 1,"Phil": 1, "Peter": 1,"Olaf": 1,"Phoebus": 1, "Ralph": 1, "Robin": 1, "Bambi": 2, "Belle": 2,"Bolt": 2, "Mulan": 2,"Mowgli": 2,"Mickey": 2,"Silver": 2,"Simba": 2,"Stitch": 2, "Dumbo": 3, "Genie": 3,"Jiminy": 3, "Kyzko": 3,"Kida": 3,"Kenai": 3,"Tarzan": 3,"Tiana": 3,"Winnie": 3, } # кол-во писем n = int(raw_input()) # list с именами адресатов inputMailFrom = [] # цикл по заполению адресатов for n in range(n): inputMailFrom.append(mailBox.get(raw_input())) step = [] if len(inputMailFrom) == 1: if inputMailFrom[0] == 1: print (0) if inputMailFrom[0] == 2: print (1) if inputMailFrom[0] == 3: print (2) else: for i in range(n): step.append(abs(inputMailFrom[i]-inputMailFrom[i+1])) print (sum(step) Try this 2 Tiana Aurora The correct answer is 4. Initially he stands near the leftmost case, but the first letter does not need to be sent to the first case. | WA #6 ??? | Александр | 2023. Donald is a postman | 2 Oct 2018 09:15 | 2 | n=int(input()) s1=['Alice','Ariel','Aurora','Phil','Peter','Olaf','Phoebus','Ralph','Robin' ] s2=['Bambi','Belle', 'Bolt','Mulan','Mowgli','Mickey','Silver','Simba','Stitch'] s3=['Dumbo','Genie','Jiminy','Kuzko','Kida','Kenai','Tarzan','Tiana','Winnie'] a=s1 k=0 for i in range(n): s=input() if s in s1: if a==s1: continue elif a==s2: k+=1 a=s1 elif a==s3: k+=2 a=s1 elif s in s2: if a==s1: k+=1 a=s2 elif a==s2: continue elif a==s3: k+=1 a=s2 elif s in s3: if a==s1: k+=2 a=s3 elif a==s2: k+=1 a=s2 elif a==s3: continue print(k)
elif s in s3: if a==s1: k+=2 a=s3 elif a==s2: k+=1 a=s2 Wait, doesn't this letter is sent to block s3, why a = s2? | AC_Sol in c++ | Adkham | 2023. Donald is a postman | 22 Aug 2018 15:58 | 2 | #include<iostream> #include<string> using namespace std; int main() { string box1[3][3] = { "Alice", "Ariel","Aurora", "Phil", "Peter", "Olaf", "Phoebus", "Ralph", "Robin" }; string box2[3][3] = { "Bambi", "Belle", "Bolt", "Mulan", "Mowgli", "Mickey", "Silver", "Simba", "Stitch" }; string box3[3][3] = { "Dumbo", "Genie", "Jiminy", "Kuzko", "Kida", "Kenai", "Tarzan", "Tiana", "Winnie" }; int n, step; string names; bool here1, here2, here3; here2 = here3 = false; here1 = true; step = 0; cin >> n; for (int m = 0; m < n; m++) { cin >> names; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (box1[i][j] == names) { here1 = true; if (here2) { step++; } else if (here3) { step = step + 2; } here2 = false; here3 = false; break; } } } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (box2[i][j] == names) { here2 = true; if (here1) { step++; } else if (here3) { step++; } here1 = false; here3 = false; break; } } } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (box3[i][j] == names) { here3 = true; if (here2) { step++; } else if (here1) { step = step + 2; } here1 = false; here2 = false; break; } } } } cout << step << endl; return 0; } #include <iostream> #include <string> #include <cmath> int32_t get_post_case_offset(const std::string& receiver) { uint32_t out = 0; switch (receiver[0]){ case 'A': case 'P': case 'O': case 'R': out = 0; break;
case 'B': case 'M': case 'S': out = 1; break; default: out = 2; } return out; } std::string get_receiver(){ std::string out; std::cin >> out; return std::move(out); } int main() { uint32_t n; std::cin >> n; uint32_t steps = 0; int32_t last_offset = 0;
for (;n;n--){ int32_t offset = get_post_case_offset(get_receiver()); steps += abs(last_offset - offset); last_offset = offset; } std::cout << steps << std::endl;
return 0; } | WA #3 Why it is not working? | Koloskova Mariia | 2023. Donald is a postman | 20 Jul 2018 14:21 | 3 | #include<iostream> #include<string> using namespace std; int main() { int n,k=0; char t,s; cin>>n; string a[1001]; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<n-1;i++) { t=a[i][0]; s=a[i+1][0];
if((t=='A' || t=='P' || t=='O' || t=='R') && (s=='A' || s=='P' || s=='O' || s=='R')) k+=0; if((t=='A' || t=='P' || t=='O' || t=='R') && (s=='B' || s=='M' || s=='S')) k+=1; if((t=='A' || t=='P' || t=='O' || t=='R') && (s=='D' || s=='G' || s=='J' || s=='K' || s=='T' || s=='W')) k+=2;
if((t=='B' || t=='M' || t=='S') && (s=='B' || s=='M' || s=='S')) k+=0; if((t=='B' || t=='M' || t=='S') && (s=='A' || s=='P' || s=='O' || s=='R'|| s=='D' || s=='G' || s=='J' || s=='K' || s=='T' || s=='W')) k+=1;
if((t=='D' || t=='G' || t=='J' || t=='K' || t=='T' || t=='W') && (s=='D' || s=='G' || s=='J' || s=='K' || s=='T' || s=='W')) k+=0; if((t=='D' || t=='G' || t=='J' || t=='K' || t=='T' || t=='W') && (s=='B' || s=='M' || s=='S')) k+=1; if((t=='D' || t=='G' || t=='J' || t=='K' || t=='T' || t=='W') && (s=='A' || s=='P' || s=='O' || s=='R')) k+=2; }
cout<<k; return 0; } 1 Dumbo --->>> is not working Right Answer is 2 but your answer 0 | No subject | Yusufjon | 2023. Donald is a postman | 20 Jul 2018 14:18 | 1 | Edited by author 27.07.2018 02:09 | WA but its working correct any ideas? | nasafiy | 2023. Donald is a postman | 17 Nov 2017 00:46 | 2 | #include<iostream> #include<cstdio> using namespace std; int main() { int n, a = 1, counter = 0; string s; cin >> n; for (int i = 0; i < n; ++i) { cin >> s; if (s[0] == 'A' || s[0] == 'P' ||s[0] == 'O' ||s[0] == 'R' && a == 2){ a = 1; counter++;} else if (s[0] == 'A' || s[0] == 'P' ||s[0] == 'O' ||s[0] == 'R' && a == 3){ a = 1; counter +=2;} if (s[0] == 'B' || s[0] == 'M' ||s[0] == 'S' && a == 1){ a = 2; counter++;} else if (s[0] == 'B' || s[0] == 'M' ||s[0] == 'S' && a == 3){ a = 2; counter++;} if (s[0] == 'D' || s[0] == 'G' ||s[0] == 'K' ||s[0] == 'T' || s[0] == 'W' && a == 1){ a = 3; counter +=2;} else if (s[0] == 'D' || s[0] == 'G' ||s[0] == 'K' ||s[0] == 'T' || s[0] == 'W' && a == 2){ a = 3; counter++;} } cout << counter; return 0; } You list D, G, K, T, W, but not J. | I publish the correct code, but the timus does not accept it, so that everything is normal. | Bushmanov | 2023. Donald is a postman | 24 Oct 2017 03:59 | 3 | Hello. Task number is 2023. Timus flatly refuses to accept. He had a lot of tests, but he did not find any flaws. Maybe someone will tell me, otherwise I'll kill myself tomorrow. n = int(input()) zn = [1] k=0 y = 0 sh1 = ('Alice', 'Ariel', 'Aurora', 'Phil', 'Peter', 'Olaf', 'Phoebus', 'Ralf', 'Robin') sh2 = ('Bambi', 'Belle', 'Bolt', 'Mulan', 'Mowgli', 'Mickey', 'Silver', 'Simba', 'Stitch') for j in range (n): i = input() if i in sh1: zn.append (1) elif i in sh2: zn.append (2) else: zn.append (3) n-=1 for k in range (len(zn)): y+= abs ((int(zn [k-1]))-int(zn [k])) lop = y-zn[-1]+1 print (lop) >'Ralf' Every time someone has problems with this task, it's someone who can't type text from a picture properly. Thank you. (Cnacu6o, Bbl Mou repou!) Edited by author 24.10.2017 04:00 | What wrong answer#3 | Shohruh_1999 | 2023. Donald is a postman | 10 Nov 2016 08:57 | 1 | #include<iostream> using namespace std; int n,i,k,t,j; string a[10000],b[10000],c[10000],d[10000]; int main(){ a[1]="Alice"; a[4]="Phil"; a[7]="Phoebus"; a[2]="Ariel"; a[5]="Peter"; a[8]="Ralph"; a[3]="Aurora"; a[6]="Olaf"; a[9]="Robin";
b[1]="Bambi"; b[4]="Mulan"; b[7]="Silver"; b[2]="Belle"; b[5]="Mowgli"; b[8]="Simba"; b[3]="Bolt"; b[6]="Mickey"; b[9]="Stitch";
c[1]="Dumbo"; c[4]="Kuzko"; c[7]="Tarzan"; c[2]="Genie"; c[5]="Kida"; c[8]="Tiana"; c[3]="Jiminy"; c[6]="Kenai"; c[9]="Winnie"; cin>>n; for(i=1; i<=n; i++) cin>>d[i]; for(i=1; i<=n; i++) { for(j=1; j<=9; j++) if(d[i]==a[j]){ if(t==0) k+=0; if(t==1) k+=1; if(t==2) k+=1; if(t==3) k+=2; t=1; break; } for(j=1; j<=9; j++) if(d[i]==b[j]){ if(t==0) k+=0; if(t==1) k+=1; if(t==2) k+=1; if(t==3) k+=1; t=2; break; } for(j=1; j<=9; j++) if(d[i]==c[j]) { if(t==0) k+=0; if(t==1) k+=2; if(t==2) k+=1; if(t==3) k+=1; t=3; break; } } cout<<k; } | С# Solution | zak427 | 2023. Donald is a postman | 29 Jun 2016 14:31 | 1 | using System; namespace Csharp_2023 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int num = 1; int sum = 0; for (int z = 1; z <= n; z++) { string str1 = Console.ReadLine(); for (int f = 1; f <= n; f++) { if (str1[0] == 'A' || str1[0] == 'P' || str1[0] == 'O' || str1[0] == 'R') { if (num == 1) sum += 0; else if (num == 2) sum += 1; else if (num == 3) sum += 2; num = 1; break; } else if (str1[0] == 'B' || str1[0] == 'M' || str1[0] == 'S') { if (num == 1) sum += 1; else if (num == 2) sum += 0; else if (num == 3) sum += 1; num = 2; break; } else if (str1[0] == 'D' || str1[0] == 'G' || str1[0] == 'J' || str1[0] == 'K' || str1[0] == 'T' || str1[0] == 'W') { if (num == 1) sum += 2; else if (num == 2) sum += 1; else if (num == 3) sum += 0; num = 3; break; } } } Console.WriteLine(sum); } } } | Here is my ac code and very simple to undestand on c++ | nick nikuradze | 2023. Donald is a postman | 8 May 2016 01:03 | 1 | #include <iostream> using namespace std; int main() { int n; cin>>n; string s; int a=1; int counter=0; for(int i=0; i<n; i++) { cin>>s; if((s[0]=='A' || s[0]=='P' || s[0]=='R' || s[0]=='O' ) && a==2) { a=1; counter++;} else if((s[0]=='A' || s[0]=='P' || s[0]=='R' || s[0]=='O' ) && a==3) { a=1; counter+=2;} else if((s[0]=='B' || s[0]=='M' || s[0]=='S') && a==1){ a=2; counter++;} else if((s[0]=='B' || s[0]=='M' || s[0]=='S') && a==3){ a=2; counter++;} else if((s[0]=='D' || s[0]=='G' || s[0]=='J' || s[0]=='K' || s[0]=='T' || s[0]=='W' ) && a==1) { a=3; counter+=2;} else if((s[0]=='D' || s[0]=='G' || s[0]=='J' || s[0]=='K' || s[0]=='T' || s[0]=='W' ) && a==2) { a=3; counter++;}
} cout<<counter; system("pause"); return 0; } | Test #1? Whats wrong with my code? | Shavkat_bek | 2023. Donald is a postman | 6 May 2016 18:42 | 2 | #include<iostream> #include<cstring> #include<cmath> using namespace std; int main(){ string st; int W,n,i=0,A[1000]; cin >> n; do{ cin >> st; if(((int)st[0]==65)||((int)st[0]==80)||((int)st[0]==79)||((int)st[0]==82)) A[i]=1; if(((int)st[0]==66)||((int)st[0]==77)||((int)st[0]==83)) A[i]=2; if(((int)st[0]==68)||((int)st[0]==71)||((int)st[0]==74)||((int)st[0]==75)||((int)st[0]==84)||((int)st[0]==87)) A[i]=3; i++; }while(i<n); for(i=0;i<n-1;i++) { int S; S=abs(A[i]-A[i+1]); W+=S; } cout<<W; return 0; } Please,help me!!! Edited by author 06.05.2016 18:42 | Test №6 В чем ошибка? | Mixail | 2023. Donald is a postman | 23 Apr 2016 16:15 | 2 | #include <iostream> #include <cstring> #include <string> #include <cmath> using namespace std; int shkaf(string name) { string mas1[9] = { "Alice", "Ariel", "Aurora", "Phil", "Peter", "Olaf", "Phoebus", "Ralph", "Robin" }; string mas2[9] = {"Bambi", "Belle", "Bolt","Mulan", "Mowgle", "Mickey", "Silver", "Simba", "Stitch" }; string mas3[9] = { "Dumbo", "Genie", "Jiminy", "Kuzko", "Kida", "Kenai", "Tarzan", "Tiana","Winnie" }; for (int i = 0; i < 9; i++) { if (name == mas1[i])return 1; if (name == mas2[i])return 2; if (name == mas3[i]) return 3; } } int main() { int N, s=0,a1=1,a2=1; string name; cin >> N; for (int i = 0; i < N; i++) { cin>>name; a2=shkaf(name); s += abs(a2 - a1); a1 = a2; } cout << s; return 0; } | This is my solution, and it be Accepted, C++ | Manh Le Van | 2023. Donald is a postman | 23 Apr 2016 15:55 | 3 | /* Le Van Manh Hanoi University Of Science And Technology Viet Nam */ #include <iostream> #include <stdio.h> #include <string> using namespace std; int readAddressToValue(){ int v = 0; string a; cin>>a; if( a=="Alice"||a=="Ariel"||a=="Aurora"|| a=="Phil"||a=="Peter"||a=="Olaf"|| a=="Phoebus"||a=="Ralph"||a=="Robin"){ v = 0; }else if( a=="Bambi"||a=="Belle"||a=="Bolt"|| a=="Mulan"||a=="Mowgli"||a=="Mickey"|| a=="Silver"||a=="Simba"||a=="Stitch"){ v = 1; }else{ v = 2; } return v; } int main(){ int address0; int address1; int steps = 0; int n; cin>>n;
address0 = readAddressToValue(); steps+= address0 - 0; for(int i=1;i<n;i++){ address1 = readAddressToValue(); steps += abs(address1 - address0); address0 = address1; } cout<<steps; return 0; } Edited by author 20.02.2016 13:17 потому что не подключил <cmath> |
|
|