644

#include <iostream> #include <cstdio> #include <cstring> #include <string> using namespace std; struct node{ bool end; node *nxt[2]; node() { end=false; for(int i=0;i<2;i++) nxt[i]=NULL; } }*root; int main() { string str,s; int id; node *cur,*tmp; int kase=1; while(cin>>str) { bool decodable=1; root=new node(); cur=root; int i; for( i=0;i<str.size()-1;i++) { id=str[i]-'0'; if(cur->nxt[id]==NULL) { cur->nxt[id]=new node(); } cur=cur->nxt[id];

11716

#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <string> using namespace std; int main() { int t,l,m; string str; cin>>t; getchar(); while(t–) { char gr[105][105]; getline(cin,str); l=str.size(); m=sqrt(l); if(m*m!=l) { cout<<"INVALID\n"; } else { int k=0; for(int i=0;i<m;i++) { for(int j=0;j<m;j++) { gr[i][j]=str[k]; k+=1; } } for(int i=0;i<m;i++) { for(int j=0;j<m;j++) cout<<gr[j][i]; } cout<<"\n";

10703

#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #define INF 1000000 using namespace std; void swp(int *p,int *q) { int tmp; tmp=*p; *p=*q; *q=tmp; } int main() { int h,w,n; int a,b,c,d; bool gr[505][505]; while(cin>>h) { cin>>w>>n; if(h+w+n==0) break; memset(gr,0,sizeof(gr)); int cnt=0; for(int k=0;k<n;k++) { cin>>a>>b>>c>>d; if(a>c) swp(&a,&c); if(b>d) swp(&b,&d); for(int i=a;i<=c;i++) { for(int j=b;j<=d;j++)

496

Using set::set_intersect(params) the problem can be solved. #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <set> #include <algorithm> #include <sstream> #define INF 1000000 using namespace std; set<int> Set1,Set2,inn; int main() { int n; string str; stringstream ss; while(getline(cin,str)) { Set1.clear(); Set2.clear(); inn.clear(); ss.clear(); ss<<str; while(ss>>n) { Set1.insert(n); } getline(cin,str); ss.clear(); ss<<str; while(ss>>n) { Set2.insert(n);

11565

#include <iostream> #include <cmath> #include <cstdio> #include <vector> #include <algorithm> using namespace std; vector<int> vb; int main() { int t; int A,B,C; cin>>t; while(t–) { cin>>A>>B>>C; bool found=0; vb.clear(); for(int i=-100;i<=100;i++) { for(int j=-100;j<=100;j++) { for(int k=-100;k<=100;k++) { if(i+j+k==A) if(i*j*k==B) if(i*i+j*j+k*k==C) if(i!=j && i!=k && j!=k) { vb.push_back(i);vb.push_back(j);vb.push_back(k); found=1; i=101;j=101;k=101; } } } } if(found)