7.文字列処理(1)

1.A1001

#include<stdio.h> 
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	int A[5],i = 0;
	int sum = a+b;
	if(sum<0){
		printf("-");
		sum = -sum;
	}
	if(sum==0)	printf("0");
	else{
		while(sum){
			A[i++] = sum%1000;
			sum /= 1000;
		}
		printf("%d",A[i-1]);
		for(int j = i-2;j>=0;j--){
			printf(",%03d",A[j]);
		}
	}	
	return 0;
}

2.A1005

#include<stdio.h> 
#include<string.h>
char num[10][10] = {"zero","one","two","three","four","five","six","seven","eight","nine"};
int main(){
	int sum = 0;
	char str[110];
	gets(str);
	int len = strlen(str); 
	for(int i = 0;i<len;i++)
		sum += str[i] - '0';
	int i = 0,a[5] = {0};
	if(sum == 0)	printf("zero");
	else{
		while(sum!=0){
			a[i++] = sum%10;
			sum /= 10;
		}
		for(int j = i-1;j>=0;j--){
			printf("%s",num[a[j]]);
			if(j!=0)
				printf(" ");
		}
	}	
	return 0;
}

3.A1035

#include<stdio.h> 
#include<string.h>
struct node{
	char name[20],password[20];
	bool ischange;
}T[1005];
void crypt(node &t,int &cnt){
	int len = strlen(t.password);
	for(int i = 0;i<len;i++){
	if(t.password[i] == '1'){
		t.password[i] = '@';
		t.ischange = true;
		} else if(t.password[i] == '0'){
		t.password[i] = '%';
		t.ischange = true;
		}else if(t.password[i] == 'l'){
			t.password[i] = 'L';
			t.ischange = true;	
		}else if(t.password[i] == 'O'){
			t.password[i] = 'o';
			t.ischange = true;
		}
	}
	if(t.ischange){
		cnt++;
	}
}
int main(){
	int n,cnt = 0;
	scanf("%d",&n);
	for(int i = 0;i<n;i++){
		scanf("%s %s",T[i].name,T[i].password);
		T[i].ischange = false;
	}
	for(int i = 0;i<n;i++){
		crypt(T[i],cnt);
	}
	if(cnt==0){
		if(n==1)
			printf("There is %d account and no account is modified",n);
		else
			 printf("There are %d accounts and no account is modified",n);
	}else{
		printf("%d\n",cnt);
		for(int i = 0;i<n;i++)
			if(T[i].ischange == true)
				printf("%s %s\n",T[i].name,T[i].password);
	}
	return 0;
}

4.A1077

#include<stdio.h> 
#include<string.h>
int n,minlen = 256,ans = 0;
char str[100][256];
int main(){
	scanf("%d",&n);
	getchar();
	for(int i = 0;i<n;i++){
		gets(str[i]); 
		int len = strlen(str[i]);
		if(minlen > len)	minlen = len;
		for(int j = 0;j<len/2;j++){
			char temp = str[i][j];
			str[i][j] = str[i][len-j-1];
			str[i][len-j-1] = temp;
		}
	}
	for(int i=0;i<minlen;i++){
		char c = str[0][i];
		bool same = true;
		for(int j = 1;j<n;j++)
			if(c != str[j][i]){
				same = false;
				break;
			}
		if(same) 	ans++;
		else break;
	}
	if(ans){
		for(int i=ans-1;i>=0;i--)
			printf("%c",str[0][i]);
	}else{
		printf("nai");
	}
	return 0;
}

5.A1082

#include<stdio.h> 
#include<string.h>
char num[10][5] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
char wei[5][5] = {"Shi","Bai","Qian","Wan","Yi"};
int main(){
	char str[15];
	scanf("%s",str);
	int len = strlen(str);
	int left = 0,right = len - 1;
	if(str[0] == '-'){
		printf("Fu");
		left++;
	}
	while(left+4 <= right)
		right -= 4;
	while(left<len){
		bool flag = false;
		bool isPrint = false;
		while(left <= right){
			if(left>0&&str[left] == '0')
				flag = true;
			else{
				if(flag == true){
					printf(" ling");
					flag = false;
				}
				if(left>0)	printf(" ");
				printf("%s",num[str[left]-'0']);
				isPrint = true;
				if(left != right)	printf(" %s",wei[right-left-1]);
			}
			left++;
		}
		if(isPrint==true&&right!=len-1)
			printf(" %s",wei[(len-1-right)/4+2]);
		right+=4;
	}
	return 0;
}

6.B1002

#include<stdio.h> 
#include<string.h>
int main(){
	char str[110];
	gets(str);
	int len = strlen(str);
	int sum = 0;
	for(int i = 0;i<len;i++)
		sum += (str[i]-'0');
	int ans[10],num = 0;
	while(sum!=0){
		ans[num++] = sum%10;
		sum/=10;
	}
	char change[10][5] = {"ling","yi","er","san","si","wu","liu","qi","ba","jiu"};
	for(int i = num-1;i>=0;i--){
		printf("%s",change[ans[i]]);
		if(i!=0)	printf(" ");
		else printf("\n");
	}
	return 0;
}

7.B1006

#include<stdio.h> 
int main(){
	int n;
	scanf("%d",&n);
	int temp;
	temp = n/100;
	for(int i = 0;i<temp;i++)
		printf("B");
	temp = n%100/10;
	for(int i = 0;i<temp;i++)
		printf("S");
	temp = n%10;
	for(int i = 1;i<=temp;i++)
		printf("%d",i);
	return 0;
}
公開された26元の記事 ウォンの賞賛3 ビュー167

おすすめ

転載: blog.csdn.net/qq_41898248/article/details/104051722