Demo entry 6646079

lzuqer

   

Submitted by anonymous on Oct 13, 2017 at 16:58
Language: C++. Code size: 3.2 kB.

#include<bits/stdc++.h>
#include"Sales_item.h"
using namespace std;
#define MAX_NUM 36
#define MAX_GROUP (MAX_NUM/2)
map<string,int>key;
map<string,int>mp;
string prepath="C://Users//Duhao//Desktop//ans//";
string req[11]={"if","else","break","for","while","do","char","int","class","void"};
extern int crosscheck(int,int[MAX_GROUP],int[MAX_GROUP][MAX_NUM]);
int main(){
    for(int i=0;i<10;i++)key[req[i]]=1;
    int testnum=33;
    int foundnum[MAX_GROUP],foundid[MAX_GROUP][MAX_NUM];
    int groupnum;
    groupnum=crosscheck(testnum,foundnum,foundid);
    cout<<groupnum<<" identical groups are detected"<<endl;
    for(int i=0;i<groupnum;i++){
        cout<<"group "<<i+1<<": ";
        for(int j=0;j<foundnum[i];j++){
           cout<<foundid[i][j];
           if(j<foundnum[i]-1)cout<<",";
        }
        cout<<endl;
    }
}
int signcheck(char c){
	if(c==','||c==' '||c=='('||c==')'||c=='*'||c=='&'||c=='^'||c=='%'||c=='-'||c=='#'||c=='+'||c=='!'||c=='~'||c=='='||c=='{'||c=='}'||c=='['||c==']'||c=='\\'||c=='|'||c==';'||c=='\''||c=='"'||c=='<'||c=='>'||c=='?'||c=='/')return 1;
	return 0;
}
char s[1010];
vector<int> check(){
    mp.clear();
	while(gets(s)!=NULL){
		if(s[0]=='#')continue;
		int now=0,end=strlen(s),flg=0;
		if(s[0]=='\\'&&s[1]=='\\'&&end>=2)continue;
		while(now<end&&!flg){
			string res="";
			while(!signcheck(s[now])&&now<end)res+=s[now++];
			if(key[res])mp[res]++;
			while(signcheck(s[now])&&!flg){
				if(s[now]=='"'){
					now++;
					while(s[now]!='"'&&now<end)now++;now++;
				}
				else if(s[now]=='\\'){
					if(s[now+1]=='\\'&&now+1<end){
						flg=1;
						break;
					}
					now++;
				}
				else now++;
			}
		}
	}
	vector<int>v;
	for(int i=0;i<10;i++)v.push_back(mp[req[i]]);
	return v;
}
int fa[MAX_NUM+7],rk[MAX_NUM+7];
double rak[11]={0.123,0.124,0.354,0.521,0.74,0.95,0.123,0.123,0.596,0.932};
int find(int x){
    return x==fa[x]?x:fa[x]=find(fa[x]);
}
void uni(int x,int y){
    if(find(x)==find(y))return ;
    rk[find(y)]+=rk[find(x)];
    fa[find(x)]=fa[find(y)];
}
string getpath(int x){
    string tmp="";
    if(x>=10)tmp+=(char)('0'+x/10);
    tmp+=(char)('0'+x%10);
    return prepath+tmp+".cpp";
}
vector<int>v[MAX_NUM+7];
int cal(int x,int y){
    double res1=0,res2=0;
    for(int i=0;i<v[x].size();i++)res1+=rak[i]*(double)v[x][i];
    for(int i=0;i<v[y].size();i++)res2+=rak[i]*(double)v[y][i];
    return fabs(res1-res2)<=0.7;
}
map<int,int>mpp;
extern int crosscheck(int testnum,int foundnum[MAX_GROUP],int foundid[MAX_GROUP][MAX_NUM]){
    for(int i=1;i<=33;i++)fa[i]=i,rk[i]=1;mpp.clear();
    for(int i=1;i<=33;i++){
        const char* path=getpath(i).data();
        freopen(path,"r",stdin);
        v[i]=check();
    }
    for(int i=1;i<=33;i++)
        for(int j=i+1;j<=33;j++)
            if(cal(i,j))
                uni(i,j);
    int cnt=0;
    for(int i=1;i<=33;i++){
        if(rk[find(i)]<2)continue;
        if(mpp.find(find(i))==mpp.end())mpp[find(i)]=cnt++,foundnum[mpp[find(i)]]=0;
        foundid[mpp[find(i)]][foundnum[mpp[find(i)]]++]=i;
    }
    return cnt;
}

This snippet took 0.02 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).