these part shouldn't be done twice
tree can help you to solve

Moderator: Board moderators
Code: Select all
#include <iostream>
#include <string>
using namespace std;
string s;
char c;
int t,d,q,m,n,i,j;
int main()
{
cin >> t;
while(t--)
{
cin >> d;
while(d--)
{
cin >> s;
}
cin >> q;
while(q--)
{
cin >> m >> n;
cin.get();
while(m--)
{
getline(cin,s);
}
}
}
return 0;
}
Code: Select all
int main ()
{
int T, D, Q, M, N, i, j, k;
char s[2005];
cin >> T;
assert(T>=1 && T<=10);
for (k=1; k<=T; k++)
{
cin >> D;
assert(D>=1 && D<=15000);
for (i=0; i<D; i++) cin >> s;
cin >> Q;
assert(Q>=1 && Q<=100);
for (j=1; j<=Q; j++)
{
cin >> M >> N;
assert(M>=1 && M<=100 && N>=1 && N<=100);
for (i=0; i<M; i++) cin >> s;
}
}
return 0;
}
Code: Select all
int main ()
{
int T, D, Q, M, N, i, j, k;
char s[2005];
cin >> T;
assert(T>=1 && T<=10);
while (T--)
{
cin >> D;
assert(D>=1 && D<=15000);
while (D--) cin >> s;
cin >> Q;
assert(Q>=1 && Q<=100);
while (Q--)
{
cin >> M >> N;
assert(M>=1 && M<=100 && N>=1 && N<=100);
while (M--) cin >> s;
}
}
return 0;
}
Code: Select all
int main ()
{
int T, D, Q, M, N, i, j, k;
char s[2005];
cin >> T;
while (T--)
{
cin >> D;
while (D--) cin >> s;
cin >> Q;
while (Q--)
{
cin >> M >> N;
while (M--) cin >> s;
}
}
return 0;
}
Code: Select all
char buf[100000], sq[128][128];
int main()
{
int D, Q, M, N, T, t, k;
for(scanf("%d", &T), t=1; t<=T; t++)
{
scanf("%d", &D);
for(k=0; k<D; k++)
scanf("%s", buf);
scanf("%d", &Q);
for(k=1; k<=Q; k++)
{
scanf("%d %d", &M, &N);
for(i=0; i<M; scanf("%s", sq[i++]));
}
}
return 0;
}
I don't think so. I don't get any problem for reading input.Emilio wrote:Is something wrong in the input specification?
Is the file input corrupted?
Maybe, it is because the problem looks quite easy. At least everyone should know how to solve it with a brute-force method. But then, submitting the trivial solution will surely result in TLE.Emilio wrote:What is the reason why the AC rate is so slow?
Code: Select all
3 3
aaa
bbb
ccc
aaa
bbb
ccc
Code: Select all
main()
{
int tn,ct=0;
string tmp;
for (fin>>tn;tn--;)
{
for(fin>>t;t--; )
fin>>tmp;
int ttn;
fin>>ttn;
for (int tc=0;tc<ttn;tc++)
{
fin>>m>>n;
for(int i=0;i<m;i++)
for (int j=0;j<n;j++)
fin>>table[i][j];
}
}
return 0;
}
Afaik there is no difference (except that cin>> is much more slower). How do you use it? You probably have a bug in your code.Tamagodzi wrote:Try to read m and n with cin >> m >> n and surprisingly u will get wa.
Does anyone know whats the difference between cin and scanf("%d.. in reading integers?
There is definitly something wrong around some inputs for m and n which scanf can handle somehow and cin not.
Search for Aho-Corasick algorithm. It's based on KMP algorithm, but searches many patterns in a string at once.Wei-Ming Chen wrote:My code got TLE in this question.
And my method was find the first word, and checked the eight side of it. I thought it was too slow to solve this question. Can someone give me some hints to solve it?