|
|
I had a hard time with this, so hopefully I will save your time. Read input like this: int n; cin >> n; string t; getline(cin, t); // Necessary to process end of first line (nothing after n) .... // Now keep getting each line with getline(cin, t) What is in this Test? What is the difference from previous ones? There are no big numbers, no special cases - as far as I get the task... Помогите ,пожалуйста , что не так? #include <iostream> #include <string> using namespace std; int main() { int n, s = 0; cin >> n; string a[1000]; for (int i = 0; i < n; i++) { getline(cin, a[0]); for (int j = n + 1; j < n; j++) { if (a[i] == a[j]) { break; s++; } } } cout << s; return 0; } Edited by author 02.12.2019 20:46 у тебя код неверный Edited by author 18.12.2019 17:14 Edited by author 14.11.2019 22:47 The answer is correct, but it returns an error. Why? Maybe I did not understand the condition of the task correctly, or can the data be specified for which this code will produce the wrong solution? using System; namespace ConsoleApp30 { class Program { static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int x = 0; string[] shoplist = new string[n]; for (int i = 0; i <n; i++) { shoplist[i] = Console.ReadLine(); } for (int i = 0; i < shoplist.Length; i++) { for (int j = i + 1; j<shoplist.Length; j++) { if (shoplist[i] == shoplist[j]) { x++; i++; } else { continue; } } } Console.WriteLine(x); //Console.ReadKey(); } } } Edited by author 01.11.2017 20:58 Edited by author 16.02.2017 22:39 Edited by author 22.03.2016 20:56 Edited by author 22.03.2016 20:56 i have WA on test #3 my code here: #include <iostream> using namespace std; int main() { int n, s = 0; cin >> n;
string *arr = new string[n]; string a; getline(cin, a); for(int i = 0; i < n; i++) { getline(cin, a); for(int j = 0; j < i; j++) { if(a == arr[j]) { s++; break; } else arr[i] = a; } }
cout << s << endl;
return 0; } Edited by author 26.01.2016 21:58 Try test: 2 a a - Your answer is 1, expected is 0 Also your solution has O(n*n) complexity. I expect (or at least hope) you will have TLE. Edited by author 27.01.2016 18:07 Can't edit prev message. > Your answer is 1, expected is 0 Should be: Your answer is 0, expected is 1 My code: var a:array[1..1000]of string; b:array[1..1000]of integer; n,i,j,m,max:integer; s:string; c:boolean; begin readln(n); for i:=1 to n do begin c:=true; readln(s); for j:=1 to m do if s=a[j] then begin inc(b[j]); c:=false; break; end; if c then begin inc(m); a[m]:=s; inc(b[m]); end; end; for i:=1 to n do if max<b[i] then max:=b[i]; writeln(max); end. I know. I understood that the wrong.^^ can you give me 5th test, please input contains strings which size is 30. that is my code #5 test case is the error #include<iostream> #include<cstring> using namespace std; int main() { char nmat[1000][31]; long int no=0; long int n; cin>>n;
cin.ignore(); if(1<=n && n<=1000) { for(int i=0;i<n;i++) cin.getline(nmat[i],30);
for(int i=1;i<n;i++) { for(int j=i-1;j>=0;j--) { if((strcmp(nmat[i],nmat[j]))==0) { no++; break; }
} }
cout<<no; system("pause"); return 0; }
} where is non-zero exit code in my code solving Bayan problem please help me #include<iostream> #include<cstring> using namespace std; int main() { char nmat[1000][31]; int no=0; int n; cin>>n; cin.ignore(); if(1<=n&&n<=1000) { for(int i=0;i<n;i++) cin.getline(nmat[i],30); for(int i=1;i<n;i++) { for(int j=i-1;j>=0;j--) { if((strcmp(nmat[i],nmat[j]))==0) { no++; break; } } }
cout<<no; } system("pause"); return 0; } crc16 hash table is not working on test 7. someone solved using hash tables? import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class AcmTimusRu { public static void main(String[] args) { Scanner s = new Scanner(System.in); String[] strings = new String[1000]; Set<String> set = new HashSet<String>(); int n, i; n = s.nextInt(); n =n +1; for (i = 0; i < n; i++) { set.add(s.nextLine()); } if (n == set.size()) { System.out.println(0); } else { int n1 = set.size(); n1 = n - n1; System.out.println(n1); } } } Edited by author 01.05.2014 12:20 Edited by author 01.05.2014 12:20 Kornilenko Leonid (KHAI) AC [1] // Problem 1563. Bayan 22 Jan 2008 17:13 0.062s and 2125Kb I solve it on C#. With Hashtable it's very easy. p.s. GL & HF Edited by author 22.01.2008 17:18 With Python's dicts it's easier :) #include <conio.h> #include <algorithm> #include <iostream> #include <cstdio> #include <stdio.h> #include <string.h> using namespace std; int povtor (char str[31],char mas2[1001][31],int mas2len) { int i; for (i=0; i<mas2len; i++) { if (strcmp(str,mas2[i])==0) return 0; } return 1; } int main() { int N; char mas[1001][31]; char mas2[1001][31];
int mas2len=0;
cin >> N; for (int i=0; i<N; i++) { cin >> mas[i]; }
for (int i=0; i<N; i++) { if (povtor(mas[i],mas2,mas2len)) strcpy(mas2[mas2len++],mas[i]); }
cout << N-mas2len;
getch(); } I'm pass test only after add ignoring for empty input lines. why empty lines present in tests? There is no empty lines in tests. But the input is finished by EOLN, as usual on Timus Online Judge. Edited by author 17.07.2013 18:22 her's my cod! Please help! using System; namespace ConsoleApplication1 { class Program1563 { static void Main() { int n = int.Parse(Console.ReadLine()); string str; string[] strl = new string[n]; int s = -1; for (int i = 0; i < n; i++) { str = Console.ReadLine(); strl[i] = str; Console.WriteLine("i="+i); for (int j = 0; j < i; j++) { if (str == strl[j]) s++; } }
Console.WriteLine(s); Console.ReadLine(); } } }
|
|
|