m0_64726603 2022-06-29 12:54 采纳率: 59.3%
浏览 18
已结题

关于#c++#的问题,如何解决?

问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果

改成Java

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>

using namespace std;



int main()
{
    string a,b,c;

    cin >> a >> b >> c;

    int len = a.length();

    int res = 0;
    for (int i = 0; i < len; ++i) {
        set<int>s;
        s.insert(a[i]);
        s.insert(b[i]);
        s.insert(c[i]);
        if (s.size() == 2) ++res;
        if (s.size() == 3) res += 2;
    }

    cout << res << endl;

    return 0;
}

  • 写回答

1条回答 默认 最新

  • it_hao528 2022-06-29 13:28
    关注

    参考如下:

    
    public static void main(String[] args) {
        String a, b, c;
        Scanner sc = new Scanner(System.in);
        a = sc.nextLine();
        b = sc.nextLine();
        c = sc.nextLine();
        int len = a.length();
        int res = 0;
        for (int i = 0; i < len; ++i) {
            Set<String> s = new HashSet<>();
            if (i < a.length()) {
                s.add(a.substring(i, i+1));
            }
            if (i < b.length()) {
                s.add(b.substring(i, i+1));
            }
            if (i < c.length()) {
                s.add(c.substring(i, i+1));
            }
            if (s.size() == 2) ++res;
            if (s.size() == 3) res += 2;
        }
        System.out.println(res);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 6月29日
  • 已采纳回答 6月29日
  • 创建了问题 6月29日