• HDU2030


    思路

    首先需要知道:一个汉字在字符串中是以两个负的字符形式存储。(计算机中补码第一位是符号位,1为负数,所以 汉字机内码的每个字节表示的十进制数都是负数)
    所以该题我们则需要遍历字符串,找出ASCII为负的进行累加,
    因为问的是汉字个数,所以累加的结果除以2即可,
    汉字机内码:使用二个字节,每个字节最高位为1,用它来表示一个汉字,在用到这个字时,系统按这个编号去找它的点阵信息,然后把它显示出来。

    Q

    clion显示的和样例给出的答案不一样 导致我一直以为是我的代码问题
    为什么显示不对

    AC代码

    //#include<bits/stdc++.h>
    #include<iostream>
    #include<string.h>
    #include<algorithm>
    #include<stdio.h>
    #include<cmath>
    #include<list>
    #include<stdlib.h>
    #include<map>
    #include<stack>
    #include<stdio.h>
    #include<queue>
    
    using namespace std;
    typedef long long ll;
    #define sc(T) scanf("%d",&T)
    #define scc(x,y) scanf("%d %d",&x,&y)
    #define pr(T) printf("%d
    ",T)
    #define f(a,b,c) for (int a=b;a<=c;a++)
    #define ff(a,b,c) for (int a=b;a>=c;a--)
    #define inf 0x3f3f3f3f
    #define mem(a,b) memset(a,b,sizeof(a))
    #define eps 1e-9
    #define PI acos(-1)
    const int N=1e5+20;
    
    char s[N];
    
    int main()
    {
        int T;
        cin>>T;
        getchar();
        while(T--)
        {
            //getchar();
            gets(s);
            int l=strlen(s);
            //cout<<l<<"**"<<endl;
            int w=0;
            f(i,0,l-1)
            {
                if(s[i]<0)
                    w++;
            }
            cout<<w/2<<endl;
        }
        return 0;
    }
    
  • 相关阅读:
    Axure流程图
    Axure工作区间
    Axure简介
    Java知识导航总图
    SQL筛选出同一学科的时间最新的记录
    从高版本JDK换成低版本JDK报错Unsupported major.minor version 52.0
    java.lang.IllegalArgumentException: No converter found for return value of type
    httpClient创建对象、设置超时
    sql 查出一张表中重复的所有记录数据
    java List分批处理
  • 原文地址:https://www.cnblogs.com/OFSHK/p/13643783.html
Copyright © 2020-2023  润新知