|
|
My solution in Python 3 took 0.062s and 220 KB. Can it be faster? Of course it can! my solution took away just 0.001 sec and 172 kB(in C) Python takes more time than lower level languages and thats why it's not the best idea to use it in a speed based setting What's the WA 3?? and send me please some tests if u have) I didn't do anything for 'arbitary' sequence. But my solution got accepted.Can anybody help me clear this doubt? #include<iostream> #include<string> #include<map> #include<set> using namespace std; int main(){ map<char,set<string>> dic; string w; int n; cin>>n; while(--n>=0){ cin>>w; dic[w[0]].insert(w); } char c; cin>>c; for(auto s:dic[c]) cout<<s<<endl; } Edited by author 28.07.2018 15:42 using System; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int n = Convert.ToInt32(Console.ReadLine()); string [] ch= new string [100]; string c; for (int i=0;i<n;i++) ch[i]=Console.ReadLine(); c=Console.ReadLine(); for (int i=0;i<n;i++) { if (c==ch[i].Substring(0,1)) Console.WriteLine(ch[i]); } Console.ReadKey(); } } } what's the problem??? help me please Use comment for this line (or delete this line) //Console.ReadKey(); This is my code!!! #include <iostream> #include <vector> #include <algorithm> using namespace std; vector <string> str; vector <string> str1; int main() { char k; string s; vector <string> str; vector <string> str1; int n; cin>>n; for(int i=0; i<n; i++) { cin>>s; str.push_back(s); } cin>>k;
for(int i=0; i<n; i++) { if(str[i][0]==k) str1.push_back(str[i]); }
sort(str1.begin(),str1.end()); for(int i=0; i<str.size(); i++) { cout<<str1[i]<<endl; } return 0; } Do you check your code locally, using some C++ IDE or compiler? Why no? You MUST try. You can, using VS or QTCreator: - run task sample using debugger; - catch "vector index out of range" exception/failure; - fix it. Edited by author 23.04.2016 20:06 I check it on c++ compiler and it do right You definitely didn't check. Your code contains mistakes. Your code must fail with some "vector index out of range" error when you run it locally in debug mode. Probably you use "checked" in meaning "compiled without errors". It is wrong meaning. I check it on c++ compiler and it do right Find the solution and explanation of this task in manyprogrammingtutorials.blogspot.com So,it's easy problem. just use array and charAt(0); I think that code is easy to understand. If you got WA, try it. #include <iostream> #include <map> using namespace std; int main() { map<char, string> m; int n; cin >> n; while (n--) { char c1, c2; cin >> c1 >> c2; m[c1].push_back(c2); } char c; cin >> c; for (int i = 0; i < m[c].size(); ++i) cout << c << m[c][i] << endl; return 0; } using System;namespace jama{class Program{static void Main(string[] args){ushort n = ushort.Parse(Console .ReadLine());string[] a = new string[n];for (ushort i = 0; i <= n - 1; i++){a[i] = Console.ReadLine();}string b = Console.ReadLine();foreach (string d in a){if (d.Substring(1,1) == b)Console.WriteLine(d);}Console.ReadLine();}}} #include<stdio.h> #include<stdlib.h> #include<string.h> int main() { int n,i,j=0; char a[100][4]; char b; scanf("%d",&n); for(i=0;i<=n;i++) { gets(a[i]); } scanf("%c",&b); for(i=0;i<=n;i++) { if(a[i][j]==b) { puts(a[i]); } } return 0; } there can be more than 100 hieroglyphs This is my code var n,i:integer; baza:array[1..1000]of string[2]; tmp,bukva:string[2]; begin read(n); i:=0; repeat i:=i+1; readln(baza[i]); until i=n; read(bukva); for i:=1 to n do begin tmp:=baza[i]; if bukva=tmp[1] then writeln(tmp); end; end. Where mystake? I think to this code is right, but i have WA in test1. Help please tmp:=baza[i]; if bukva=tmp[1] then writeln(tmp); mistake there. Edited by author 23.12.2011 13:14 np, i have proceed :D Edited by author 23.08.2011 02:26 program t1545; var s,h:array [1..1000] of string; p:array [1..1000] of longint; x,k:string; a,b,n,i,j,m,l:longint; begin readln(n);a:=1; for i:=1 to n do readln(s[i]); readln(k); b:=length(k); for i:=1 to n do begin l:=0; x:=s[i]; for j:=1 to length(s[i]) do begin if x[j]=k[1] then begin for m:=0 to b-1 do if x[j+m]=k[m+1] then inc(l); if l=b then begin h[a]:=x; inc(a); end; end; end; end; for i:=1 to a-1 do begin l:=0; x:=h[i]; for j:=1 to length(x) do begin if x[j]<>k then l:=l+ord(x[j]); end; p[i]:=l; end; for i:=1 to a-2 do for j:=i+1 to a-1 do begin if p[i]>p[j] then begin l:=p[i]; p[i]:=p[j]; p[j]:=l; k:=h[i]; h[i]:=h[j]; h[j]:=k; end; end; for i:=1 to a-1 do writeln(h[i]); end. If I'm not mistaking, the string in Pascal can't be longer than 255 symbols. But may be I am... oh men ! what are you doing ? is this the program we want to write??? try this type myarray=array [1..1000] of string; var i,n:integer; a:myarray; s,s1:string; begin readln (n); for i:=1 to n do readln (a[i]); readln (s); for i:=1 to n do begin s1:=a[i]; if s1[1]=s then writeln (a[i]) end; end. I create alphabetic-sorted binary tree and find strings in it. I got WA 11, why? #include <iostream> using namespace std; int main() { int n; int i; char s; char a[1001]; cin>>n;
for (i = 0; i<n*2; i++) cin>>a[i]; cin>>s; for (i=0; i<n*2; i++) {
if (s == a[i] && i % 2 == 0) cout<<a[i]<<a[i+1]<<endl; }
system("pause"); return 0; } a[1001] should be a[2000] at least; I've just understood!! 1<=n<=1000 not n<=100 =))! Edited by author 28.01.2011 00:34 |
|
|