ideone和Codeforces中相同程序的不同输出
Different output for same program in ideone and Codeforces
问题http://codeforces.ru/contest/518/problem/B我提交了解决方案。这是解决方案的视频链接-http://ideone.com/ucGGgA
在Ideone中,测试用例4的输出与Codeforces中的输出不同。
Input -
zzzzz
ZZZZZ
Output-
in Ideone - 0 5
In Codeforces - 5 0
编辑-这是解决方案-
//#include<bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <stack>
#include <cmath>
#include <queue>
#include <string>
#include<climits>
#include<set>
#include<list>
#include<sstream>
using namespace std;
#define mod 1000000007
#define tr(c,i) for(auto i=(c).begin(); i != (c).end(); i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define forup(i,a,b) for(int i=(a);i<=(b);i++)
#define tcsolve() int tcs; cin >> tcs; forup(tc, 1, tcs) solve();
#define mp(a,b) make_pair(a,b)
inline void gi(int &x) {
register int c = getchar();
x = 0;
int neg = 0;
for (; ((c<48 || c>57) && c != '-'); c = getchar());
if (c == '-') {
neg = 1;
c = getchar();
}
for (; c>47 && c<58; c = getchar()) {
x = (x << 1) + (x << 3) + c - 48;
}
if (neg)
x = -x;
}
inline void print(int a){ char s[20]; int i = 0; do{ s[i++] = a % 10 + '0'; a /= 10; } while (a); i--; while (i >= 0)putchar(s[i--]); putchar('n'); }
void solve()
{
string str1, str2, ans;
int mp[1000];
rep(i, 100)
{
mp[i] = 0;
}
cin >> str1 >> str2;
int yay=0, woops=0;
rep(i, str2.length())
{
mp[str2[i]]++;
}
rep(i, str1.length())
{
if (mp[str1[i]] > 0)
{
yay++;
mp[str1[i]]--;
}
else
{
if (str1[i] >= 'a' && str1[i] <= 'z')
{
if (mp[str1[i] - 'a' + 'A'] > 0)
{
woops++;
mp[str1[i] - 'a' + 'A']--;
}
}
else if (str1[i] >= 'A' && str1[i] <= 'Z')
{
if (mp[str1[i] + 'a' - 'A'] > 0)
{
woops++;
mp[str1[i] + 'a' - 'A']--;
}
}
}
}
cout << yay << " " << woops << "n";
}
int main()
{
solve();
}
较短(MCVE)版本的解决方案-
#include <cstdio>
#include <iostream>
#include <map>
#include <cstdlib>
#include <string>
using namespace std;
void solve()
{
string str1, str2, ans;
int mp[1000];
for (int i = 0; i < 100;i++)
{
mp[i] = 0;
}
cin >> str1 >> str2;
int yaya = 0, woops = 0;
for (int i = 0; i < str2.length();i++)
{
mp[str2[i]]++;
}
for (int i = 0; i < str1.length(); i++)
{
if (mp[str1[i]] > 0)
{
yaya++;
mp[str1[i]]--;
}
else
{
if (str1[i] >= 'a' && str1[i] <= 'z')
{
if (mp[str1[i] - 'a' + 'A'] > 0)
{
woops++;
mp[str1[i] - 'a' + 'A']--;
}
}
else if (str1[i] >= 'A' && str1[i] <= 'Z')
{
if (mp[str1[i] + 'a' - 'A'] > 0)
{
woops++;
mp[str1[i] + 'a' - 'A']--;
}
}
}
}
cout << yaya << " " << woops << "n";
}
int main()
{
solve();
}
在第一个循环中,您不会初始化所有值:
int mp[1000];
for (int i = 0; i < 100; i++) // 100 and not 1000
{
mp[i] = 0;
}
因此任何以后对CCD_ 1的访问都具有未定义的值。
您可以直接写入int mp[1000] = {};
来用0
初始化mp
。
相关文章:
- 如何从Windows应用程序输出到标准?
- 在由Sublime文本3编译后在cmd上显示Java程序输出
- 如何从 Win32 C++ 应用程序输出到父控制台窗口?
- 而循环:简单的除法程序输出零,不明白为什么
- Qt creator 4.11,在应用程序输出面板中创建一个链接
- 使用复制构造函数的程序输出错误
- 为什么Qt Creator的应用程序输出不能从spdlog记录器打印
- 为什么在 Direct X 11 中没有我的程序输出?
- 我怎样才能阻止我的程序输出时间,它使我的程序难以阅读
- 程序输出奇怪的字符
- 程序输出"nan"
- 为什么我的C++程序输出不同的数字来将米转换为英尺?
- 3D 纹理大小会影响程序输出,而不会引发错误
- C++,程序输出无效输入,但继续通过循环
- 如何连接C++和Excel(从C++程序输出到Excel电子表格)
- 为什么我的C 程序输出乱码代码
- QT小部件应用程序输出到控制台
- 混淆了具有虚拟继承的程序输出
- 为什么我的C++程序输出这个
- 为什么我的程序输出不断变化?EAX寄存器不断更改值