Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //CHUYỂN THÀNH CHỮ HOA
- #include<stdio.h>
- #include<ctype.h>
- #include<math.h>
- #include<string.h>
- int main(){
- int i=0;
- char str[100];
- gets(str);
- char c;
- while (str[i])
- {
- c=str[i];
- putchar (toupper(c));
- i++;
- }
- return 0;
- }
- //ĐẾM KÝ TỰ
- #include<stdio.h>
- #include<ctype.h>
- #include<math.h>
- #include<string.h>
- int main(){
- int i=0,chucai=0, chuso=0, kitukhac=0;
- char str[100];
- gets(str);
- char c;
- while (str[i])
- {
- c=str[i];
- if(isalpha(c)){
- chucai++;
- } else {
- if(isdigit(c)){
- chuso++;
- } else {
- kitukhac++;
- }
- }
- i++;
- }
- printf("%d %d %d", chucai, chuso, kitukhac);
- return 0;
- }
- //LOẠI BỎ TỪ TRONG XÂU
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void doAction(char *src, int pos, int len) {
- int i;
- int size = strlen(src);
- for(i = pos; i <= size - len; i++) {
- src[i] = src[i + len];
- }
- }
- void removeStr(char *src, char *token) {
- int i;
- int len = strlen(token);
- for(i = 0; src[i] != '\0'; i++) {
- if(strstr(&src[i], token) == &src[i]) {
- doAction(src, i, len);
- i --;
- }
- }
- }
- int main(){
- char input[1000];
- char token[100];
- fgets(input, 999, stdin);
- fgets(token, 99, stdin);
- int len = strlen(token);
- if(len > 0) {
- token[len-1] = '\0';
- }
- int size = strlen(input);
- if(size > 0) {
- input[size-1] = '\0';
- }
- removeStr(input, token);
- puts(input);
- return 0;
- }
- //LOẠI CÁC TỪ TRÙNG NHAU
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int main ()
- {
- char str[100], word[100], twoD[10][30];
- int i = 0, j = 0, k = 0, len1 = 0, len2 = 0, l = 0;
- gets (str);
- for (i = 0; str[i] != '\0'; i++)
- {
- if (str[i] == ' ')
- {
- twoD[k][j] = '\0';
- k ++;
- j = 0;
- }
- else
- {
- twoD[k][j] = str[i];
- j ++;
- }
- }
- twoD[k][j] = '\0';
- j = 0;
- for (i = 0; i < k; i++)
- {
- int present = 0;
- for (l = 1; l < k + 1; l++)
- {
- if (twoD[l][j] == '\0' || l == i)
- {
- continue;
- }
- if (strcmp (twoD[i], twoD[l]) == 0) {
- twoD[l][j] = '\0';
- present = present + 1;
- }
- }
- }
- j = 0;
- for (i = 0; i < k + 1; i++)
- {
- if (twoD[i][j] == '\0')
- continue;
- else
- printf ("%s ", twoD[i]);
- }
- printf ("\n");
- return 0;
- }
- //ĐẾM SỐ TỪ TRONG XÂU
- #include<stdio.h>
- int demkitu(char s[])
- {
- int i=0;
- while (s[i]!='\0')
- {
- i++;
- }
- return i;
- }
- int main()
- {
- int n;
- scanf("%d\n", &n);
- for (int i=1; i<=n; i++)
- {
- char s[201];
- gets(s);
- int last=demkitu(s)-1;
- while (s[last]==' ') last--;
- int count=0;
- for (int j=0; j<=last; j++)
- {
- if (s[j]!=' ' && s[j+1]==32) count++;
- if (s[j]!=' ' && s[j+1]=='\0') count++;
- }
- printf("%d", count);
- printf("\n");
- }
- return 0;
- }
- //SỐ ĐẸP 1
- #include<stdio.h>
- #include<string.h>
- int main(){
- int t;
- scanf("%d", &t);
- while(t--){
- char so[500];
- scanf("%s", so);
- int dodai = strlen(so);
- int i,le=0,check=0;
- for(i = 0; i<dodai; i++){
- if(((int)so[i]-48)%2==1){
- le++;
- }
- }
- for(i = 0; i<(dodai/2);i++){
- if(((int)so[i]-48)!=((int)so[dodai-i-1])){
- check++;
- }
- }
- if(check!=0&&le==0){
- printf("YES");
- } else {
- printf("NO");
- }
- printf("\n");
- }
- return 0;
- }
- //SỐ ĐẸP 2
- #include<stdio.h>
- #include<string.h>
- int main(){
- int t;
- scanf("%d", &t);
- while(t--){
- char so[500];
- scanf("%s", so);
- int dodai = strlen(so);
- int i,check1=0,check2=0;
- if(((int)so[0]-48)==8&&((int)so[dodai-1]-48)==8){
- check1=1;
- }
- int tong=0;
- for(i=0; i<dodai; i++){
- tong=tong+((int)so[i]-48);
- }
- if(tong%10==0){
- check2=1;
- }
- if(check1==1&&check2==1){
- printf("YES");
- }else {
- printf("NO");
- }
- printf("\n");
- }
- return 0;
- }
- //SỐ ĐẸP 3
- #include<stdio.h>
- #include<string.h>
- int SNT(int n){
- if(n<2){
- return 0;
- }
- int count = 0,j;
- for(j=2; j<=sqrt(n); ++j){
- if(n%j==0){
- count++;
- }
- }
- if(count==0){
- return 1;
- } else {
- return 0;
- }
- }
- int main(){
- int t;
- scanf("%d", &t);
- while(t--){
- char so[500];
- scanf("%s", so);
- int dodai = strlen(so);
- int i,check1=0,check2=0;
- for(i = 0; i<(dodai/2);i++){
- if(((int)so[i]-48)!=((int)so[dodai-i-1]-48)){
- check1++;
- }
- }
- for(i = 0; i<dodai; i++){
- if(SNT((int)so[i]-48)==0){
- check2++;
- }
- }
- if(check1==0&&check2==0){
- printf("YES");
- }else {
- printf("NO");
- }
- printf("\n");
- }
- return 0;
- }
- //TÁCH TỪ
- #include<stdio.h>
- #include<string.h>
- int main()
- {
- char s[100];
- gets(s);
- int dodai=strlen(s) - 1;
- int i,j;
- while(s[dodai]==' '){
- dodai--;
- }
- for(i = 0;i<=dodai;i++){
- if(s[i]==' '){
- s[i]='\n';
- }
- }
- printf("%s", s);
- return 0;
- }
- //SỐ ĐẦY ĐỦ
- #include<stdio.h>
- #include<string.h>
- int CheckHopLe(char so[], int dodai){
- int i,count=0;
- for(i = 0; i < dodai; i++){
- if(so[i]<48||so[i]>57){
- count++;
- }
- }
- if(count==0&&((int)so[0]-48)!=0){
- return 1;
- } else {
- return 0;
- }
- }
- int main(){
- int t;
- scanf("%d", &t);
- while(t--){
- char so[1000];
- scanf("%s", so);
- int dodai = strlen(so);
- int check[10];
- int i,check1=0;
- for(i = 0; i < 10; i++){
- check[i]=0;
- }
- if(CheckHopLe(so,dodai)==0){
- printf("INVALID");
- } else {
- for(i = 0; i<dodai;i++){
- check[(int)so[i]-48]++;
- }
- for(i = 0; i<10; i++){
- if(check[i]==0){
- check1++;
- }
- }
- if(check1==0){
- printf("YES");
- }else{
- printf("NO");
- }
- }
- printf("\n");
- }
- return 0;
- }
- //SỐ ƯU THẾ
- #include<stdio.h>
- #include<string.h>
- int CheckHopLe(char so[], int dodai){
- int i,count=0;
- for(i = 0; i < dodai; i++){
- if(so[i]<48||so[i]>57){
- count++;
- }
- }
- if(count==0&&((int)so[0]-48)!=0){
- return 1;
- } else {
- return 0;
- }
- }
- int main(){
- int t;
- scanf("%d", &t);
- while(t--){
- char so[1000];
- scanf("%s", so);
- int dodai = strlen(so);
- int check[10];
- int i,chan=0,le=0;
- if(CheckHopLe(so,dodai)==0){
- printf("INVALID");
- } else {
- for(i = 0; i<dodai; i++){
- if(((int)so[i]-48)%2==0){
- chan++;
- } else {
- le++;
- }
- }
- int check = 0;
- if(dodai%2==0&&chan>le){
- check = 1;
- }
- if(dodai%2==1&&le>chan){
- check = 1;
- }
- if(check==1){
- printf("YES");
- } else {
- printf("NO");
- }
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement