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 5a49130

Browse files
author
zhunago
committed
sohu
1 parent f46b003 commit 5a49130

File tree

3 files changed

+147
-0
lines changed

3 files changed

+147
-0
lines changed

‎nowcoder/sohu.1.cpp‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <unordered_map>
4+
#include <unordered_set>
5+
#include <set>
6+
#include <queue>
7+
#include <algorithm>
8+
#include <string>
9+
10+
using namespace std;
11+
12+
int main(void)
13+
{
14+
string a, b;
15+
cin >>a >>b;
16+
if(a.size() != b.size())
17+
{
18+
cout << 0 << endl;
19+
return 0;
20+
}
21+
int count = 0;
22+
vector<int> dict(26, 0);
23+
bool hastwo = false;
24+
for(int i = 0; i < a.size(); ++i)
25+
{
26+
dict[a[i] - 'a'] += 1;
27+
if(dict[a[i] - 'a'] >= 2)
28+
{
29+
hastwo = true;
30+
}
31+
if(a[i] != b[i])
32+
{
33+
count += 1;
34+
if(count > 2)
35+
{
36+
cout << 0 << endl;
37+
return 0;
38+
}
39+
}
40+
}
41+
if(count == 1)
42+
cout << 0 << endl;
43+
else if(count == 2)
44+
cout << 1 << endl;
45+
else if(count == 0 && hastwo)
46+
cout << 1 << endl;
47+
else
48+
cout << 0 << endl;
49+
50+
return 0;
51+
}

‎nowcoder/sohu.2.cpp‎

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include <iostream>
2+
#include <string>
3+
4+
using namespace std;
5+
6+
int getnextNumber(const string &s, unsigned int &index)
7+
{
8+
int num = 0;
9+
while (index < s.size() && isdigit(s[index]))
10+
{
11+
num = num * 10 + s[index] - '0';
12+
index++;
13+
}
14+
return num;
15+
}
16+
17+
int compareVersionNumber(const string& x, const string& y) {
18+
unsigned int indexx = 0;
19+
unsigned int indexy = 0;
20+
while (indexx < x.size() && indexy < y.size())
21+
{
22+
int verx = getnextNumber(x, indexx);
23+
int very = getnextNumber(y, indexy);
24+
if (verx > very) return 1;
25+
if (verx < very) return -1;
26+
indexx += 1;
27+
indexy += 1;
28+
}
29+
if (indexx >= x.size() && indexy >= y.size()) return 0;
30+
if (indexx < x.size())
31+
{
32+
bool notzero = false;
33+
while (indexx < x.size())
34+
{
35+
int verx = getnextNumber(x, indexx);
36+
indexx += 1;
37+
if (verx != 0)
38+
{
39+
notzero = true;
40+
break;
41+
}
42+
}
43+
if (notzero)
44+
return 1;
45+
else return 0;
46+
}
47+
bool notzero = false;
48+
while (indexy < y.size())
49+
{
50+
int very = getnextNumber(y, indexy);
51+
indexy += 1;
52+
if (very != 0)
53+
{
54+
notzero = true;
55+
break;
56+
}
57+
}
58+
if (notzero)
59+
return -1;
60+
else return 0;
61+
62+
}
63+
64+
int main() {
65+
string x;
66+
string y;
67+
cin >> x >> y;
68+
cout << compareVersionNumber(x, y);
69+
return 0;
70+
}

‎nowcoder/sohu.cpp‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
6+
int main(void)
7+
{
8+
int target;
9+
cin >> target;
10+
int cur = 0;
11+
int step = 0;
12+
target = abs(target);
13+
while(cur < target)
14+
{
15+
step += 1;
16+
cur += step;
17+
}
18+
19+
while((cur - target) % 2 != 0)
20+
{
21+
step += 1;
22+
cur += step;
23+
}
24+
cout << step << endl;
25+
return 0;
26+
}

0 commit comments

Comments
(0)

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