Skip to content

Commit 6f562da

Browse files
authored
Add files via upload
0 parents  commit 6f562da

File tree

2 files changed

+215
-0
lines changed

2 files changed

+215
-0
lines changed

1_from_CB.cpp

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
//#include <bits/stdc++.h>
2+
//using namespace std;
3+
//int main()
4+
//{
5+
// map< int , int >mp;
6+
// int arr[]={5, 5 , 2 , 3};
7+
// for(int i = 0 ; i < 4 ; i++)
8+
// {
9+
// mp[arr[i]]++;
10+
// }
11+
//
12+
//}
13+
14+
15+
16+
17+
#include <bits/stdc++.h>
18+
using namespace std;
19+
int main()
20+
{
21+
int tc;
22+
cin>>tc;
23+
int k = 1;
24+
25+
while(tc--)
26+
{
27+
int trc = 0;
28+
int n;
29+
cin>>n;
30+
//map< int , int > mp;
31+
vector< vector<int> > v;
32+
v.resize(n,vector<int>(n));
33+
//int *count = new int[sizeof(int)*(n)];
34+
//unordered_map<int, int> mp;
35+
for(int i = 0 ; i<n ; i++)
36+
{
37+
for(int j = 0; j<n; j++)
38+
{
39+
cin>>v[i][j];
40+
if( i == j ) trc += v[i][j];
41+
}
42+
}
43+
int cnt1 =0;
44+
int cnt2 =0;
45+
int cntTmp1 = 0;
46+
int cntTmp2 = 0;
47+
/// Setting Values
48+
49+
for (int i = 0; i < n; i++) {
50+
cnt1 =0; cnt2 =0;
51+
unordered_map<int, int> mpR;
52+
unordered_map<int, int> mpC;
53+
for (int j = 0; j < n; j++) {
54+
mpR[v[i][j]]++;
55+
}
56+
for (int j = 0; j < n; j++) {
57+
mpC[v[j][i]]++;
58+
}
59+
60+
for (int j = 0; j < n; j++) {
61+
if(mpR[v[i][j]] > 1 ) cnt1++;
62+
}
63+
64+
for (int j = 0; j < n; j++) {
65+
if(mpC[v[j][i]] > 1 ) cnt2++;
66+
}
67+
68+
if(cnt1>1) cntTmp1++;
69+
//cout<<cntTmp1<<" ";
70+
71+
if(cnt2>1) cntTmp2++;
72+
//cout<<cntTmp2<<" ";
73+
}
74+
75+
// for (int i = 0; i < n; i++) {
76+
// for (int j = 0; j < n; j++) {
77+
// cout<<mp[v[i][j]]<<" ";
78+
// }
79+
// }
80+
81+
// for (auto itr = mp.begin(); itr != mp.end(); itr++) {
82+
//// if (itr->second % 2 == 0) {
83+
//// int x = itr->second;
84+
//// sum += (itr->first) * (itr->second);
85+
//// }
86+
//
87+
// cout<<itr->first*<<" "<<itr->second<<endl;
88+
// }
89+
90+
91+
92+
93+
// }t<<endl;
94+
cout<<"Case #"<<k++<<": "<<trc<<" "<<cntTmp1<<" "<<cntTmp2<<endl;
95+
}
96+
97+
}
98+
99+
100+
// for(int i = 1 ; i<=n ; i++)
101+
// {
102+
// for(int j = 1; j<=n; j++)
103+
// {
104+
// mp[v[i][j]] = 1;
105+
//
106+
// }
107+
// }
108+
109+
110+
111+
112+
113+
114+
// //mp[v[i][j]] = 1;
115+
// if(mp[v[i][j]] == 1){
116+
// cnt++;
117+
// cout<<cnt<<" ";
118+
// }
119+
// else
120+

2_from_CB_2nd_Version.cpp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
string getString(char x)
4+
{
5+
string s(1, x);
6+
7+
return s;
8+
}
9+
string givesParentesis(char a ,char b)
10+
{
11+
string res = "";
12+
int x = a - '0';
13+
int y = b - '0';
14+
if(a>b)
15+
{
16+
int tmp = (x-y);
17+
while(tmp--)
18+
{
19+
res = res + ")";
20+
}
21+
}
22+
else
23+
{
24+
int tmp = (y-x);
25+
while(tmp--)
26+
{
27+
res = res + "(";
28+
}
29+
}
30+
return res;
31+
32+
}
33+
34+
int main()
35+
{
36+
int tc;
37+
int z = 1;
38+
cin>>tc;
39+
while(tc--)
40+
{
41+
string st;
42+
cin>>st;
43+
string sttmp = "";
44+
string update = "";
45+
for(int i=0 ; i<st.size()-1;i++)
46+
{
47+
sttmp = getString(st[i])+givesParentesis(st[i],st[i+1]) ;
48+
update = update+sttmp;
49+
50+
}
51+
update = update + getString(st[st.size()-1]);
52+
// cout<<endl<<"final update "<<update<<endl;
53+
54+
//cout<<update<<" + \\\\\\\\\\\\\\\\\\\\/"<<endl;
55+
/// Work For 1st Parenthesis
56+
string blank = "";
57+
//string s1;
58+
59+
int k = st[0]-'0';
60+
while(k--)
61+
{
62+
blank = blank + "(";
63+
}
64+
sttmp = blank + update;
65+
// cout<<sttmp<<" 1st "<<endl;
66+
/////////////////////////////////
67+
68+
/// Work For last Parenthesis
69+
k = st[st.size()-1]-'0';
70+
blank = "";
71+
while(k--)
72+
{
73+
blank = blank + ")";
74+
}
75+
sttmp = sttmp + blank ;
76+
77+
cout<<"Case #"<<z++<<": "<<sttmp<<endl;
78+
79+
80+
}
81+
82+
}
83+
84+
// cout<<" getString(st[i]) "<<getString(st[i])<<endl;
85+
// cout<<" givesParentesis(st[i],st[i+1]) "<<givesParentesis(st[i],st[i+1])<<endl;
86+
// cout<<" st.substr(i+1,st.size()-1) "<<st.substr(i+1,st.size()-1)<<endl<<endl;
87+
88+
89+
/*if(st[i]>st[i+1])*/
90+
//else sttmp = ""+st.substr(i,i)+givesParentesis(st[i],st[i+1])+st.substr(i+1,st.size()-1);
91+
/*getString(st[i+1])*/
92+
//sttmp = ""+getString(st[i])+givesParentesis(st[i],st[i+1])+st.substr(i+1,st.size()-1);
93+
// cout<<sttmp<<"last"<<endl;
94+
95+
//////////////////////////////////

0 commit comments

Comments
 (0)