/* ALGORITHM: In any substring that is encountered the most, at least one letter of that substring should be encountered the same time as the substring. So, we just need to find the most encountered symbol in the string. */ using System; using System.Linq; class Program { static void Main() { Console.WriteLine((from u in Console.ReadLine().ToArray() group u by u into gg orderby gg.Count() descending select gg.Key).ToList()[0]); } } Power of Python :) from collections import Counter print(Counter(input().strip()).most_common(1)[0][0]) Power of C/C++ int main() { //shitcode_fiveloops } // AC :) #include <The Power of me!> int main() { ThePowerOfMe.makeItAC(); } ...AC!:) Edited by author 25.04.2014 16:46 I think that one line could be enough. Console.WriteLine(input.GroupBy(c => c).OrderByDescending(g => g.Count()).First().Key); // the power of C++ :) #include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main() { string s; cin >> s;
vector<int> v(30, 0); for (int i=0; i<s.size(); ++i) { ++v[s[i]-'a']; } auto c = distance(v.begin(), max_element(v.begin(), v.end())); cout << (char)('a'+c); return 0; } I think in future I will be a powerfull programmer Бред. В самом деле, достаточно искать символ, который чаще всего встречается.... так не работает работает, не мне одному приходят в голову умные мысли... What answer in this case? "Output any of the most powerful spells..." Any of them. My Source import java.util.*; public class JavaApplication3 {
public static void main(String[] args) { String SubPalabra1=""; String SubPalabra2=""; String Correcta="";
String Verdadera=""; int menor; String resto=""; Scanner D=new Scanner(System.in); String palabra=D.nextLine().trim(); if(palabra.length()!=1){ for(int i=0;i<palabra.length();i++){ Verdadera=""; resto=palabra.substring(i+1, palabra.length()); if(resto.indexOf(palabra.charAt(i))!=-1){ SubPalabra1=""+palabra.charAt(i)+resto.substring(0,resto.length()); SubPalabra2=""+resto.substring(resto.indexOf(palabra.charAt(i)),resto.length()); if(SubPalabra1.length()<SubPalabra2.length()){ menor=SubPalabra1.length(); } else{ menor=SubPalabra2.length(); } for(int j=0;j<menor;j++){
if(SubPalabra1.charAt(j)==SubPalabra2.charAt(j)){ Verdadera=Verdadera+SubPalabra1.charAt(j); if(Verdadera.length()>Correcta.length()){ Correcta=Verdadera; } } else{ j=menor; } } }
} } else{ System.out.println(palabra); } System.out.println(Correcta);
} } Who is the word that no work? #include <bits/stdc++.h> using namespace std; const int N = 112345; int a[N]; int b[N]; main() { string s, t; cin >> s; int cnt = 0; int mx=0; int l=0; int cnte=0; for(int i = s.size() - 1; i >= 0; i --) { t = s[i] + t; a[0] = 0; for(int j = 1; j < t.size(); j ++) { int x = a[j - 1]; while(x > 0 && t[x] != t[j]) x = a[x - 1]; if(t[x] == t[j]) x ++; a[j] = x; mx = max(mx, a[j]); } b[i]=mx; if(mx==0)cnte++; mx=0; } if(cnte==s.size()){cout<<s;return 0;} else for(int i=0;i<s.size();i++){if(b[i]>=1)cout<<s[i];} } // any suggestion guys I have no idea what can be the fifth test thanks in advance What is the 10th test? i dont know but i would like to share something with you. Did u know if the input is : qwertasnuqwertxsqwertplqwert the answer is not "qwert",the answer is "e" !!! помогите, что в нём?!?! спасибо, за помощь ) так. с 16-м разобрался, но что же на 28 ? It is guaranteed that the most often appeared letter is the right answer. Only one letter is needed. This problem is just to troll you. I first thought of doing it using suffix array. Just read the question properly, it says 'any substring'? Didn't you see constraint bro -_- Length is 50 and suffix array :V One single letter count! Of course, Any substring would include one letter. Here is my code, what's the problem? #include <algorithm> #include <iostream> #include <vector> #include <sstream> #include <string> #include <cstdlib> #include <cstdio> #include <iomanip> using namespace std; int main(){ int count[26]; int max = 0; char answer = '-'; for (char p = 'a'; p < char('z') + 1; p++) { count[p] = 0; } char c; while (cin.get(c)) { count[c]++; } for (char p = 'a'; p < char('z') + 1; p++) { if (count[p] > max){ max = count[p]; answer = p; } } cout << answer; } it said that the powerful spell is depend on the times it had repeated so in "abababa" "a" is 4 times or "ba" is 3... or in "qqq" whats the answer ?? "q" 3 times or "qqq" 1 time??? This topic is devoted to trolled ppl :D God damn it I was ashamed after typing so many string super duper cumbersome functions XD #include<iostream> #include<stdio.h> #include<string.h> using namespace std; char v[53];int ch[53]; char vi[53][5],*punt=NULL,vf[53],vc[53],vp[53],*a,vt[53],chr[3]; int maxl=0,maxt=0,k,b,max2,l=0; int n,j=0,i,ind; main() { gets(v); n=strlen(v); if(n==1){cout<<v;} else{ for(i=0;i<n-1;i++) { // carga inicial vi[i][0]=v[i] ; vi[i][1]=v[i+1] ; ch[i]=0; } for(i=0;i<n-1;i++) { punt=strstr(v,vi[i]); if(punt!=NULL) { ch[punt-v]++; } } for(i=0;i<n-1;i++) { if(ch[i]>maxt) { maxt=ch[i]; ind=i; } } strcpy(vc,vi[ind]); strcpy(vp,v); punt=strstr(v,vi[ind]); i=0; strcpy(vf,vi[ind]); if (maxt!=0) { while(1) { b=1; punt=strstr(v,vf); chr[0]=punt[2+l]; strcat(vf,chr); k=2+l; k++; l++; if(l==strlen(punt))break; max2=0; strcpy(vp,v); while(1) { punt=strstr(vp,vf); if(punt!=NULL) { j=strlen(punt); for(i=0;i<j-1;i++) { vp[i]=punt[i+1]; } vp[i]='\0'; max2++; if (max2>=maxt) { maxt=max2; strcpy(vc,vf); b=0; } } if(punt==NULL)break; } if(b==3) break; } } cout<<vc; }} i can't understand this about problem. who can help me? please. give me some test and with correct answer. I'm waiting for you. is in your example abababa right answer aba or only a??? because a is 4 and aba is 3. test №1: "abababa" ; correct answer: "a" test №2: "abcde" ; correct answer: "abcde" For "abcde" correct: a, b, c, d, e, ab, bc, cd, de, abc, bcd, cde, abcd, bcde, abcde Edited by author 15.11.2010 10:11 why correct answer is "a" , in my opinion answer must be "ababa" cause prefix is like that 0 0 1 2 3 4 5 Hello, How can my program get AC even it returns wrong answer for the first test? import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter;
public class SandrosBook {
public static void main(String args[]) throws IOException{
InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); PrintWriter out=new PrintWriter(System.out);
int[] a=new int[26];
String s=br.readLine(); int i=1; int start=0,end=0; start=s.charAt(0)-97; int max=0;
while(i<s.length()){ char c=s.charAt(i); a[(int)c-97]++; i++; }
int k=0; for(int ii=0;ii<26;ii++){ if(a[ii]>max) { max=a[ii]; k=ii; } }
k=k+97;
System.out.println((char)k); out.flush(); }
} try test: b right answer "b", but you output "a" Edited by author 09.03.2012 14:09 |
|