WA #5 What's wrong? Here is my code: var a,b,c:array [1..3,1..3] of string; d,s,i,j,j1,n,p:longint; x:string; begin a[1,1]:='Alice'; a[1,2]:='Ariel'; a[1,3]:='Aurora'; a[2,1]:='Phil'; a[2,2]:='Peter'; a[2,3]:='Olaf'; a[3,1]:='Phoebus'; a[3,2]:='Ralph'; a[3,3]:='Robin'; b[1,1]:='Bambi'; b[1,2]:='Belle'; b[1,3]:='Bolt'; b[2,1]:='Mulan'; b[2,2]:='Mowgli'; b[2,3]:='Mickey'; b[3,1]:='Silver'; b[3,2]:='Simba'; b[3,3]:='Stitch'; c[1,1]:='Dumbo'; c[1,2]:='Genie'; c[1,3]:='Jiminy'; c[2,1]:='Kuzko'; c[2,2]:='Kida'; c[2,3]:='Kenai'; c[3,1]:='Tarzan'; c[3,2]:='Tiana'; c[3,3]:='Winnic'; readln (n); s:=0; p:=1; for i:=1 to n do begin readln (x); for j:=1 to 3 do for j1:=1 to 3 do begin If x=a[j,j1] then d:=1; If x=b[j,j1] then d:=2; If x=c[j,j1] then d:=3; end; s:=s+abs (p-d); p:=d; end; writeln (s); end. Re: WA #5 Winnie, not Winnic Edited by author 11.10.2014 17:58 Edited by author 11.10.2014 17:58 Re: WA #5 Why so dufficult solution? You could use switch/case for only first letters! Re: WA #5 Switch? Ha! How about sets? Re: WA #5 Posted by Egor 15 Sep 2015 02:20 No need for sets: First, initialize positions of the names: 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; Then check where we are: ... string s; cin >> s; char c = s[0]; if (m[c] != current_position) ... Edited by author 15.09.2015 02:21 Edited by author 15.09.2015 02:21 Edited by author 15.09.2015 02:22 Edited by author 15.09.2015 02:22 Re: WA #5 Posted by ELDVN 1 Nov 2015 13:09 My solution: #include <iostream> #include <string> #include <vector> #include <set> #include <queue> #include <map> #include <stack> #include <algorithm> #include <bitset> #include <cstring> #include <cmath> #include <cstdlib> #include <cstdio> #include <iomanip> #define F first #define S second #define ll long long #define len length() #define sqr(x) x*x #define pb push_back #define mp make_pair #define sz(x) ((int) (x).size()) #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define bp(x) __builtin_popcount(x) #define INF numeric_limits<long long int>::max() #define frp freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++) const int maxn = (int)1e6; const int mod = (int)1e9 + 7; using namespace std; int n; string s; int step,cnt=1; int ans; main(){ scanf("%d",&n); for(int i=0; i < n; i++){ cin>>s; for(int j=0; j <s.len; j++){ switch(s[j]){ case 'A':case 'P':case 'O':case 'R':ans=1;break; case 'B':case 'M':case 'S':ans=2;break; case 'D':case 'G':case 'J':case 'K':case 'T':case 'W': ans=3;break; } } step+=abs(cnt-ans); cnt=ans; } printf("%d",step);
return 0; } |