check your last string after FOR. I missed this but now Accepted. Try this tests INPUT tram OUTPUT Tram driver INPUT tram.tram trolleybus OUTPUT Tram driver Edited by author 10.03.2010 23:01 Test 6 is <tram,> or <trolleybus,>. (whitout <>) ;-) Edited by author 28.02.2014 17:38 i need some test... i guess the mistake is about "tram", i don't know which pattern of "tram*" should be counted I had a WA25 when didn't count last word. I assume there are empty lines there #include<bits/stdc++.h> using namespace std; map<string,int>mp; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; string tr="tram"; string tro="trolleybus"; string last=""; while(getline(cin,s)) { string subject=s; regex re("\\w+"); sregex_iterator next(subject.begin(), subject.end(), re); sregex_iterator end; while (next != end) { smatch match = *next; last=match.str(); if(last==tr) mp[tr]++; else if(last==tro) mp[tro]++; next++; } } if(mp[tro]>mp[tr]) cout<<"Trolleybus driver"<<endl; else if(mp[tr]>mp[tro]) cout<<"Tram driver"<<endl; else cout<<"Bus driver"<<endl; } That's the code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace _1612trams_b { class Program { static void Main(string[] args) { string[] sArray = Console.In.ReadToEnd().Split(); char[] separator = { ' ', ',', '.', '\n', '-', ':', '!', '?' }; //string[] sArray = Console.ReadLine().Split(separator); int numTram = 0, numTrol = 0; foreach (string s in sArray) if (s == "tram") numTram++; else if (s == "trolleybus") numTrol++; if (numTram > numTrol) Console.WriteLine("Tram driver"); else if (numTram < numTrol) Console.WriteLine("Trolleybus driver"); else Console.WriteLine("Bus driver"); //Console.Read(); } } } Can anyone tell a test that can go wrong here? //#pragma GCC optimize("Ofast,no-stack-protector") //#pragma GCC target("avx") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds; using namespace std;
#define re return #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define fi first #define se second #define sqrt(x) sqrt(abs(x)) #define mp make_pair #define pi (3.14159265358979323846264338327950288419716939937510) #define fo(i, n) for(int i = 0; i < n; ++i) #define ro(i, n) for(int i = n - 1; i >= 0; --i) #define unique(v) v.resize(unique(all(v)) - v.begin())
template <class T> T abs (T x) { re x > 0 ? x : -x; } template <class T> T sqr (T x) { re x * x; } template <class T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; } template <class T> int sgn (T x) { re x > 0 ? 1 : (x < 0 ? -1 : 0); }
typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<string> vs; typedef double D; typedef long double ld; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef unsigned long long ull; typedef tree <pair<int, char>, null_type, less<pair<int, char>>, rb_tree_tag, tree_order_statistics_node_update> _tree; int main() { string a = "tram", b = "trolleybus", str; int ans = 0; while (cin >> str) { fo(i, (int)str.size() - (int)a.size() + 1) { if (str.substr(i, a.size()) != a) continue; if (!i && (str.size() == a.size() || 'a' > str[a.size()] || str[a.size()] > 'z')) ++ans; if (i && ('a' > str[i - 1] || str[i - 1] > 'z') && (i + a.size() == str.size() || 'a' > str[i + a.size()] || str[i + a.size()] > 'z')) ++ans; } fo(i, (int)str.size() - (int)b.size() + 1) { if (str.substr(i, b.size()) != b) continue; if (!i && (str.size() == b.size() || 'a' > str[b.size()] || str[b.size()] > 'z')) --ans; if (i && ('a' > str[i - 1] || str[i - 1] > 'z') && (i + b.size() == str.size() || 'a' > str[i + b.size()] || str[i + b.size()] > 'z')) --ans; } } if (ans > 0) cout << "Tram driver\n"; else if (ans < 0) cout << "Trolleybus driver\n"; else cout << "Bus driver\n"; } String symbols = "`~!№*@#$%^&*()-_=+\\|[{]};:'\",<.>/?в„– \n\r\t"; ;) Input: trams trolleybuses trambus bus Output: Bus driver Input: tram tramtrolleybus bus Output: Tram driver Input: trams trolleybus trolleybus tram! tram. Output: Bus driver Input: bus bus tratrolleybus trolleybu tra. Output: Bus driver Input: trams trolleybuses trambus bus Output: Bus driver Input: tram tramtrolleybus bus Output: Tram driver Input: trams trolleybus trolleybus tram! tram. Output: Bus driver Input: bus bus tratrolleybus trolleybu tra. Output: Bus driver Thanks a lot... :) check this test: tram,tram Right answer is Tram driver :) Edited by author 29.01.2015 16:30 My code in Python from sys import stdin a=stdin.read() tab={} for x in range(256): if not chr(x).isalpha(): tab[x]=32 a=a.translate(tab) a=a.split() tram=a.count('tram') trol=a.count('trolleybus') if tram>trol: print("Tram driver") elif trol>tram: print('Trolleybus driver') else: print('Bus driver') Edited by author 13.11.2014 17:21 "-|[.|,|!|?|-|:|\t|\n|\r|\\s]" check this test: tram.tram what output should be? bus driver? tram driver? tram driver =) Test 22 is tram,tram or trolleybus,trolleybus - check this )) Hello, pleaze help me to read data correctly in Java. I've spend a lot of time with no result. Who can tell test 24? May b someone also got in trouble with this test. Could you please check my submissions. The accepted one (I actually copy-pasted it from this forum) gives wrong answer to the following data set: tram (only 4 symbols in input.txt file) The output is "Bus driver". My original solution (#4725054) gives "Tram driver" answer to the mentioned data set, but fails on test #6. Can you please give information what is wrong with this test? Thank you. Last line of input data is always terminated with end of line character (it is the usual rule of Timus Online Judge), so this test is incorrect. Ok, got this. So I assume the problem is on my side. Will try to find what is wrong anyone knows test 6, I have been with this problem for 1 hour test 6 should take account ",.?!-: " // ----------SOLVED------------ using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { /* Here we include all word separators */ string[] ss = Console.In.ReadToEnd().Split(new char[] { ' ', '\t', '\n', '\r','.',',','!','?','-',':'}, StringSplitOptions.RemoveEmptyEntries); /* From the word list select just "tram" and "trolleybus" by Grouping we know how many times these words appear by ordering we make sure that "tram" comes first in the list r[] if both words appear in the input */ var r = (from u in ss where u == "tram" || u == "trolleybus" group u by u into uu orderby uu.Key select new { key=uu.Key, count=uu.Count() } ).ToList(); /* The rest is just printing the output basing on the results of the query */ if (r.Count == 0) Console.WriteLine("Bus driver"); else if (r.Count == 1) Console.WriteLine("{0}", r[0].key == "tram" ? "Tram driver" : "Trolleybus driver"); else if (r[0].count > r[1].count) Console.WriteLine("Tram driver"); else if (r[0].count < r[1].count) Console.WriteLine("Trolleybus driver"); else Console.WriteLine("Bus driver"); } } Edited by author 07.01.2012 01:46 cuz it's very very bad Edited by author 07.01.2012 01:46 Please people help! Can anybody tell me test 24? const tr='tram'; trol='trolleybus'; mmm=' `~!@#$%^&*()-_=+\\|[{]};:\",<.>/?¹0123456789'; var tr1,tr2,a,b,c,i:integer; s:widestring; begin b:=1; tr1:=0; tr2:=0; c:=0; while(not seekEOF)do begin c:=0; readln(s); while(pos(tr,s)>0)do begin c:=0; for i:=1 to 45 do if(s[pos(tr,s)+4]=mmm[i])then inc(c); if(pos(tr,s)+4=length(s))then inc(c); if((ord(pos(tr,s)+4)=39)or(ord(pos(tr,s)+4)=96))then inc(c); if(c=0)then begin delete(s,pos(tr,s),4); end else begin inc(tr1); delete(s,pos(tr,s),4); end; end; c:=0; while(pos(trol,s)>0)do begin c:=0; for i:=1 to 45 do if(s[pos(trol,s)+10]=mmm[i])then inc(c); if(pos(trol,s)+10=length(s))then inc(c); if((ord(pos(trol,s)+10)=39)or(ord(pos(trol,s)+10)=96))then inc(c); if(c=0)then begin delete(s,pos(trol,s),10); end else begin inc(tr2); delete(s,pos(trol,s),10); end; end; inc(b); end; if(tr1>tr2)then writeln('Tram driver') else if(tr2>tr1)then writeln('Trolleybus driver') else if(tr2=tr1)then writeln('Bus driver'); end. P.S. Sorry for bad English. Edited by author 31.05.2011 00:05 Now is AC. Two small mistakes... Edited by author 01.12.2011 22:52 now AC, a small mistake... |
|