漢字統計
漢字在字串中以兩個負數的形式儲存,所以只要算出負數個數,除以2就可以了
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=1000;
char str[maxn];
int main()
{
int n;
while(cin>>n){
getchar();
while(n--){
gets (str);
int sum=strlen(str),cnt=0;
for(int i=0;i<sum;i++)
if(str[i]<0) cnt++;
cout<<cnt/2<<"\n";
}
}
return 0;
}
相關推薦
題解報告:hdu 2030 漢字統計
中漢字 nbsp for include put 特點 input rep return 題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=2030 Problem Description 統計給定文本文件中漢字的個數。 Inpu
HDU-漢字統計
HDU-漢字統計 題目: 統計給定文字檔案中漢字的個數。 Input 輸入檔案首先包含一個整數n,表示測試例項的個數,然後是n段文字。 Output 對於每一段文字,輸出其中的漢字的個數,每個測試例項的輸出佔一行。 [Hint:]從漢字機內碼的特點考慮~ Sample Input
湖北民族學院 OJ HBMY 2265: 漢字統計
題目描述 統計給定文字檔案中漢字的個數。 輸入描述 輸入檔案首先包含一個整數n,表示測試例項的個數,然後是n段文字。 輸出描述 對於每一段文字,輸出其中的漢字的個數,每個測試例項的輸出佔一行。 輸入樣例 2 WaHaHa! WaHaHa! 今年過
漢字統計
漢字在字串中以兩個負數的形式儲存,所以只要算出負數個數,除以2就可以了 #include <iostream> #include <cmath> #include <cstdio> #include <cstring> using nam
HDOJ 2030 漢字統計
漢字的ascii碼是小於0的 統計ascii碼小於0的個數,一個漢字佔兩個位元組,所以最後要除以2 #include<iostream> #include<cstdio> #include<cstring> using namespace std; in
HDU-2030——漢字統計
漢字統計 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 62459 Accepted Submission(s): 33621 P
hdoj 2030 漢字統計 (漢字機內碼特點) C++
#include<iostream> #include<string> using namespace std; int main() { int n; string a; cin>>n; g
利用位運算統計文字文件中的漢字字數
在做C++教材練習題時,其中一題要求統計文字文件中的漢字個數,當我直接按char ch做的時候,發現統計出的字數和文字文件的位元組數相同。why? 也就是說,常規方法下統計的實際不是文字文件中的字元個數,而是這些字元的位元組和。 下面是我原先的程式碼: #include <io
如何在C語言程式中統計輸入漢字的個數
C中的漢字用“機內碼”,一個漢字兩位元組,最高位都是1,所以可以用下列程式碼求得一個字串裡漢字的個數: #include<stdio.h> #include<string.h> int main() { char s[1000]; int cn,i,all; whil
JAVA 統計字串中的漢字、英文字母、數字、其他符號的數量
</pre><pre name="code" class="html">去除字串的空格方法: 1. String.trim() trim()是去掉首尾空格 2.str
正則匹配大小寫字母、漢字、特殊字元,並統計次數
<?php header('Content-Type:text/html;charset=utf-8'); $subject='[email protected] 是
Java統計一篇文章中出現次數最多的漢字或英文單詞 又出現次數的統計
思想是用到了Map集合的鍵唯一性儲存漢字或者單詞,單詞的獲取通過正則獲取: 統計類: import java.util.ArrayList; import java.util.Map; import java.util.Set; import java.util.Tree
c++實現文字中英文單詞和漢字字元的統計
1.統計文字中漢字的頻數,為後續的文字分類做基礎。對於漢字的統計,需要判斷讀取的是否為漢字。原始碼如下: [C++ code] /* *@author:鄭海波 http://blog.csdn.
C#練習——統計整型陣列中不重複數字的個數、將普通日期格式轉換成漢字日期格式、在控制檯錄入每個學生的姓名,當用戶輸入quit(不區分大小寫)時,程式停止接受使用者的輸入,並且顯示出使用者輸入的學生的個數
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ReviewPractice { class Pr
PHP統計包含漢字的字元長度 ( 改善Smarty modifier.truncate.php 中文支援)
在網上看到關於漢字的個數統計,弄得很複雜,其實很簡單,只要正則表示式寫得得當,兩三行程式碼就能統計出來。 <?php $a ="我愛程式設計,我愛PHP" ; $b = preg_replace("/[/x{4e00}-/
String中統計數字,字母,漢字等個數
首先要分兩個方面來區分,第一種是不需要轉換成char陣列的,另一種是需要轉換成char陣列的; 1.使用String進行比較: 1>這裡為了取出部分字串,我們用到了String中的substring方法,在此方法中你可以輸入開始和結束的
java統計檔案中字元,數字,漢字,空格數目
別人發的一個題目: java上機實現統計D://document/file.txt檔案中出現的字母個數、數字個數、漢字個數、空格個數及行數? 自己實現了下: import java.io.BufferedReader; import java.io.File;
oc 之中的 漢字字符串轉化成為拼音 漢字字符串的排序
art 例如 orm plugin 也看 新的 with 替換空格 thunder 在oc 之中的字符串為漢字的時候,我們經常要進行字符串比較,可是漢字不能比較,所以就要將漢字轉化成為拼音,詳細步驟例如以下: //可變字符串 必須是可變字符串. NSMutabl
linux 文件大小和數量統計
linux 文件大小 數量統計因需要監控節點的文件狀態(時間 擁有者 大小 數目)開始監控文件數目用的 find ./ -type f |wc -l 監控文件大小 du -sk出現的問題: 1、同樣的文件在不同版本(centos6.5和centos5.8)的系統上大小不一致 c
【C語言】統計數字在排序數組中出現的次數
語言 個數 統計 ret r+ () class tdi times //數字在排序數組中出現的次數。 //統計一個數字在排序數組中出現的次數。比如:排序數組{1,2,3,3,3,3,4,5}和數字3,因為3出現了4次,因此輸出4. #include <stdio