用输出半角和全角字符

#include <stdio.h>
#include <string.h>


int main()  
{  
	char szText[] = "我是CIW.";  
	char szChinese[3] = {0};  
	
	int i = 0, nLen = strlen(szText);  
	for(; i < nLen; i++)  
	{  
		if( szText[i] >= 0 && szText[i] <= 127 ) //不是全角字符?
		{
			printf("%c\n", szText[i]);  
		}
		else									//是全角字符  
		{
			szChinese[0] = szText[i];
			szChinese[1] = szText[i + 1];
			printf("%s\n", szChinese);
			i++;								//中文是2个字节,所以i++  

		}
	}  
	return 0;  
}

计算文件大小


#include <sys/types.h>   
#include <sys/stat.h>   
#include <iostream.h>
#include <string>

using namespace std;

int getFileSize(string sFileName)
{
    struct stat buf;
    int iRet = stat(sFileName.c_str(), &buf);
    if (iRet == -1)
        return NULL;
    return buf.st_size;
}

void main()
{
	int i = getFileSize("E:\\反恐精英csV1.6中文版.exe");
	cout<<i<<endl;
}


去除字符串空格 反转字符串


#include<iostream>
#include<string>

using namespace std;

void  strallcut(char *str)
{
    int i,j=0;
    char sp[512];
    for (i = 0; *(str + i) != '\0'; i++) {
        if (*(str + i) == ' ' )
            continue;
        sp[j++]=*(str + i);
    }
    sp[j] = 0;
    strcpy(str, sp);
} 

void reverse(char s[])
{
	for(int i=0,j=strlen(s)-1;i<j;++i,--j)
	{
		int c = s[i];
		s[i] = s[j];
		s[j] = c;
	}
}
void main()
{
	char temp[100] = "  hello  zhangsan word  ";
	cout<<temp<<endl;
	strallcut(temp);
	cout<<temp<<endl;
	reverse(temp);
	cout<<temp<<endl;
}


统计文档中单词出现的次数


#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <map>

using namespace std;

void main()
{
	
	ifstream read;
	typedef map<string,int> instrmap;
	instrmap coll;
	map<string,int>::iterator it1;
	ofstream display("word.txt");
	read.open("words.txt");
	coll.clear();
	while(!read.eof())
	{
		string word;
		read>>word;
		coll[word]++;
	}
	for(it1 = coll.begin();it1 != coll.end();it1++)
	cout<<it1->first<<" "<<it1->second<<endl;
	if (!display)
	{
		cout<<"不能打开文件 word.txt"<<endl;
	}
	for(it1 = coll.begin();it1 != coll.end();it1++)
	{
		if (it1->first!="the"&&it1->first!="an"&&it1->first!="a"&&it1->first!="but"&&it1->first!="and"&&it1->first!=" ")
		{
			display<<"单词"<<it1->first<<" "<<"出现了"<<it1->second<<"次"<<endl;
		}
			
	}

	read.close();
	display.close();

	
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值