Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5bb7a72

Browse files
A problem from uri online judge was solved, 1211 is the problem
1 parent fca8d47 commit 5bb7a72

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

‎Online Judges/URI/1211.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <algorithm>
4+
5+
using namespace std;
6+
7+
/*
8+
problem: XVI Maratona de Programação IME-USP, 2012.
9+
URL: https://www.beecrowd.com.br/judge/pt/problems/view/1211
10+
*/
11+
12+
int main() {
13+
int n, cont = 0, equals = 0;;
14+
15+
16+
vector<string>phone;
17+
18+
while(cin >> n) {
19+
cont = 0;
20+
phone.assign(n, "");
21+
for(int i = 0; i < n; i++)
22+
cin >> phone[i];
23+
24+
sort(phone.begin(), phone.end());
25+
26+
for (int i = 1; i < n; i++) { // run starting from 2 phone
27+
equals = 0;
28+
for (int j = 0; j < (int)phone[i].size(); j++) { // verifying all chars from phone and comparing with the previous one
29+
/*
30+
535456
31+
535488 <-
32+
835456
33+
34+
*/
35+
if (phone[i][j] == phone[i-1][j]) {
36+
equals++;
37+
} else {
38+
break; // finished the prefix with equal numbers
39+
}
40+
}
41+
cont+=equals; // 4
42+
}
43+
44+
cout << cont << endl;
45+
}
46+
return 0;
47+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /